Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 52275  / 2 Years ago, wed, june 1, 2022, 6:28:29

I setup a Trusty VM with Django + Nginx (other stuffs too).



The server is working, I get the "Welcome to Django" page. But when I enter to servername/admin it loads the HTML page but fails to load the static content.



And the admin page have this links to static content:



<link rel="stylesheet" type="text/css" href="/static/admin/css/base.css" />
<link rel="stylesheet" type="text/css" href="/static/admin/css/login.css" />


Both of the CSS files give me 404, as the Nginx log shows:



192.168.56.1 - - [05/Jun/2014:12:04:09 -0300] "GET /admin HTTP/1.1" 301 5 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"
192.168.56.1 - - [05/Jun/2014:12:04:09 -0300] "GET /admin/ HTTP/1.1" 200 833 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"
192.168.56.1 - - [05/Jun/2014:12:04:10 -0300] "GET /static/admin/css/base.css HTTP/1.1" 404 142 "http://ubuntu-server/admin/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"
192.168.56.1 - - [05/Jun/2014:12:04:10 -0300] "GET /static/admin/css/login.css HTTP/1.1" 404 142 "http://ubuntu-server/admin/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0"


I think that the error is on my nginx.conf file, but no idea how to solve it. This is the site tree:



screenshoot



Major files: urls.py, settings.py.


More From » server

 Answers
3

This is most likely a problem of configuration in django or Nginx



There are two things you want to check:




  1. Are your staticfiles configured correctly in settings.py? For the basic django page, these settings are not necessary, but for your static files, you need to configure static files. That is not necessary for production use, because there the webserver serves the static files. Are they collected? Once configured you might have to run python manage.py collectstatic.



    For instance,



    #settings.py
    INSTALLED_APPS += [django.contrib.staticfiles,]
    STATIC_URL = '/static/'
    STATIC_ROOT = '/your_path/.../static/'

    # This collects all files in /static/ directories and puts them in the static ROOT folder.
    python manage.py collectstatic

  2. Django does not serve static files by itself (unless you set DEBUG=True in settings.py), thus you will have to add a configuration in engine x to make it serve the static files. You might have to restart nginx and/or add autoindex on; to your config for /static/ in nginx.conf.




See Deploying static files.



In development, you might also have to add the /static/ url to your urls.py (in development) and not just the settings.


[#24788] Thursday, June 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
afyess

Total Points: 437
Total Questions: 120
Total Answers: 107

Location: San Marino
Member since Fri, Jul 3, 2020
4 Years ago
afyess questions
;