#i added a background image and now my i keep getting error 500
57 messages ยท Page 1 of 1 (latest)
<!DOCTYPE html>
<head>
{%load static%}
<link rel="stylesheet" href="{{static/styles.css}}">
{%load bootstrap5%}
{% bootstrap_css %}
{% bootstrap_javascript %}
</head>
<body>
</body>
body {
background-image: url('../images/hero.jpg');
}
these are the files :(
I think you're supposed to use {% static, not {{static. See https://docs.djangoproject.com/en/5.2/howto/static-files/#configuring-static-files
i still have error 500
Did you change href as href="{% static 'styles.css' %}" ?
Also check STATIC_URL setting, and your style.css file has correct dir.
i changed the href
and this is my STATIC_URL
STATIC_ROOT = BASE_DIR / 'staticfiles'
STATIC_URL = 'static/'
the css file is in a css folder in static folder dont know if thats important
Then you give me exact error message? Also current css file's path.
it just show "Server Error (500)"
Can you open the browser's dev tool, and check network tab? Then, give me where error happens.
Or pleas check this reference.
https://docs.djangoproject.com/en/5.2/intro/tutorial06/
how do i open dev tools
For chrome, if you using window, press F12. If you using mac, press command+option+i
I don't know your project's structure, and with only 500 error message, it's hard to answer. But would you try to change href="{% static 'styles.css' %}" to href="{% static 'css/styles.css' %}"?
I think your current structure seems like below.
static
- css
- styles.css
- images
- hero.jpg
If so, you need to change like above.
How are you running the server? Django development server in debug mode, what is tutorial suggests and default for starting will give verbose error with python traceback
Debugging "there was some error" is a unprofessional guess work and waste of time
I'm running it on the development server and idk what to say cause the only error i have is 500 theres is nothing else ๐
What is in the console?
(the console where you started the development server, it will output errors there)
[10/Sep/2025 08:08:22] "GET / HTTP/1.1" 500 145
[10/Sep/2025 08:08:22] "GET /favicon.ico HTTP/1.1" 404 140
Show your full view please.
Do you happen to use try-except in it?
Only other case to get an exception without any error I can think of is raising it yourself
from django.http import HttpResponse
from django.template import loader
def landing(request):
template = loader.get_template('landing.html')
return HttpResponse(template.render(request))
this is my view file
no its false
Why? Set it to true, you WANT debug mode during development
And it's default as I mentioned earlier
That's why it must be hiding the error
Why are you rendering the page so oddly? Have you completed the official django tutorial ?
I am also waugely thinking that all load's must be at the top of the file, not inlike like this?
Is it odd? It's just verbose
Yeah, might be it
im using the w3schools tutorial ๐
please don't
Based on other w3schools tutorials i have seen they are .... bad
i turn on debug and it says
In template C:\Users\ldtec\Documents\Coding\Websites\L.D\env\luminary_designs\clients\templates\landing.html, error at line 4
Could not parse the remainder: '/styles.css' from 'css/styles.css'```
what website should i use to learn django then??
Right it's missing ""
@oak ore Welcome to the server! Here are some resources to get you started:
Tutorials
What to do after a tutorial?
FAQS
You can load multiple libs in one tag btw {% load static bootstrap5 whateverelse %}
{% static "css/styles.css" %} to be more correct, I though brackets were already mentioned
<link rel="stylesheet" href={% static "css/styles.css" %}>
like this??
yes.
I forgot if it needs additional '' around it
But all this is stuff the official tutotial would have learned you. https://docs.djangoproject.com/en/5.2/intro/
no, href="{% static "css/styles.css" %}">
TypeError: context must be a dict rather than WSGIRequest.
again, this is probably beacause of you/the w3 tutorial using such low-level code to render the tempalte in your view code .... Imho, throw it all away and start on the official tutorial.