The django admin background prompts that there is no static style-related file, djangostatic

Source: Internet
Author: User

The django admin background prompts that there is no static style-related file, djangostatic
Symptom:

DEBUG = TEMPLATE_DEBUG = False
If this parameter is set to False, the admin background is accessed and no style is available. Solution: vim settings. py: Make sure there are the following two lines.
STATIC_URL = '/static/'STATIC_ROOT = '/var/searchlog/static/'
The following is the configuration file for nginx. conf. I added a section with color in it. I used uwsgi to pull django. So here nginx will forward/to the corresponding port, and then I added a/static file. Here, the younger brother made a mistake due to Path Problems, put it in the directory under/root, but it never works. Then, put it under the/var directory. I hope no brother will commit this second illness.
[root@VM_58_36_centos var]# egrep -v '#|^$' /etc/nginx/nginx.confworker_processes  2;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    server {        listen       80;        server_name  localhost;        location /static {            alias /var/searchlog/static/;        }        access_log /var/log/nginx_access.log;        error_log /var/log/nginx_error.log;        location / {            uwsgi_pass 127.0.0.1:9099;            include /etc/nginx/uwsgi_params;        }        access_log off;        error_page   500 502 503 504  /50x.html;        location = /50x.html {            root   html;        }    }}[root@VM_58_36_centos var]# 

 

Next, let's take a look at the uwsgi. ini configuration file.
[root@VM_58_36_centos searchlog]# cat uwsgi.ini[uwsgi]vhost = falseplugins = pythonsocket = 127.0.0.1:9099master = trueenable-threads = trueworkers = 10wsgi-file = /var/searchlog/searchlog/wsgi.pychdir = /var/searchlog/[root@VM_58_36_centos searchlog]#

If you want to use uwsgi to pull django, you can directly copy this configuration and change wsgi-file and chdir to wsgi. py file, and the project directory. Let's stop talking about this. The port used above is 9099. Note that I am using nginx. in the conf configuration file, it is forwarded to the port 127.0.0.1: 9099. The two must correspond, that is, nginx will forward/access to the port 9099 of uwsgi.

In this way, you can. Run the following command: Run uwsgi.
uwsgi --ini /var/searchlog/uwsgi.ini &
The above static folder is directly generated using python manage. py collectstatic. The procedure is as follows. set STATIC_ROOT = '/var/searchlog/static/' In The py configuration file and then run python manage. py collectstatic, so that django will put the corresponding static files under the static directory. Finally, let's take a look at the tree directory of the project, "some static files are omitted here, or too many files are missing":
1 [root @ VM_58_36_centos var] # tree searchlog/2 searchlog/3 | -- db. sqlite3 4 | -- log 5 | -- _ init __. py 6 | -- admin. py 7 | -- migrations 8 | -- _ init __. py 9 | -- models. py10 | -- templates11 | -- 404.html 12 | -- 500.html 13 | -- base.html 14 | -- login.html 15 | -- logout.html 16 | -- search.html 17 | -- showlog.html 18 | -- tests. py19 | -- views. py20 | -- manage. py21 | -- searchlog22 | -- _ init __. py23 | -- settings. py24 | -- urls. py25 | -- wsgi. py26 | -- static27 | '-- admin28 | -- css29 | -- base.css 30 | '--............ <omitted here some content> 31 | -- img32 | -- changelist-bg.gif33 | -- gis34 | -- move_vertex_off.png35 | '-- move_vertex_on.png36 | -- icon-no.gif37 | | -- icon-unknown.gif38 | '--............ <some content is omitted here> 39 | '-- js40 | -- LICENSE-JQUERY.txt41 | -- actions. min. js42 | -- admin43 | -- DateTimeShortcuts. js44 | '-- RelatedObjectLookups. js45 | -- calendar. js46 | '--............ <some content is omitted here> 47 '-- uwsgi. ini48 49 [root @ VM_58_36_centos var] #
In this way, we can summarize the corresponding steps: 1. in settings. in py, STATIC_URL = '/static/'static _ ROOT ='/var/searchlog/STATIC/'has these two configurations. 2. in nginx. add the configuration location/static {alias/var/searchlog/static/;} to the configuration file of conf. You can directly use the static file configured by nginx.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.