Problem with CSS styling in a html page in Django

Viewed 28

So, i am literarily one week into learning web development and i'm following this Django tutorial, i got the index page that i swiped from online to compile properly with it's static elements also. Ran the "python3 manage.py collectstatic" command and everything.

So now i'm linking a registration page which i setup up as a new app in the project and when i try and put the css styling file it doesn't work. i've tried just puting in the same directory as the html templates, then i've moved it to styles and rerun the earlier python command so it's also present in assets, also made use of the "{% static 'abcde.css' %}" as well as {% load static %} in the register.html (only did it in the index initially) and i'm still having no luck with styling the page, any help would be appreciated

Edit:

I previously said i moved the css file but i meant the static file and run gatherstatics again so theres a copy in assets as well.

2 Answers

So now i'm linking a registration page which I setup up as a new app in the project and when i try and put the css styling file it doesn't work.

You should not put it in the same directory as the templates, nor in the directories for templates at all. It should be in a directory you use for static files, so the path is relative to the static root.

This thus means that if /static/ is the directory you marked with the STATIC_ROOT settingĀ [Django-doc], and the file is located at /static/foo/bar.css, you use {% static 'foo/bar.css' %}.

I figured it out but I don't think I should be deleting my stack overflow question. It was just a simple syntax problem

what i had: {% static 'styles/style.css' % } what you need: {% static 'styles/style.css' %}

that gap between the percentage and bracket was the problem

Related