Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting existing css/html page into Django

I have a jQuery/CSS/html webpage. I wanted to add some backend with Python/Django. I put that page (index.html) + all dependent css and js files into the templates folder (inside the Django project folder). I added the address to that page to the urls.py file and models.py file. When I run the server and try to access that page, it displays but without css styles and javascript code. So, it seems like it misses taking css and js files from that html webpage. What's wrong? What I've missed?

like image 945
user1460819 Avatar asked Dec 28 '25 09:12

user1460819


2 Answers

With Django, the static files are separated from the main web page templates. See the documentation on static files for more information.

like image 109
icktoofay Avatar answered Dec 30 '25 21:12

icktoofay


Use {% static %} method with every CSS and JS reference.

If href = "stackoverflow.jpeg" then adjust your code as follows :

href = "{% static 'stackoverflow.jpeg'%}"

Do the same with every piece of JS and CSS code.

like image 39
Arshdeep Singh Avatar answered Dec 30 '25 22:12

Arshdeep Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!