在pythonanywhere中部署的django项目中链接静态文件时出错 [英] Error in linking static files in django project deployed on pythonanywhere

查看:187
本文介绍了在pythonanywhere中部署的django项目中链接静态文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在pythonanywhere中部署了一个django(1.7)项目,其链接是 - http://drchitradhawle.pythonwherewhere。 com / 我想有静态文件链接和bootstrap.Plz有问题,任何人帮我解决问题也告诉我整个过程链接django项目中的任何静态文件和引导。



我的项目结构是 -

  home 
- DrChitraDhawle
-website
-webpage
-static
-css
-images
-templates
-website
-settings。 py

settings.py文件是 -

  STATIC_ROOT =/ home / DrChitraDhawle / website / pages / static
STATIC_URL ='/ static /'
STATICFILES_DIR =(
,'/ home / DrChitraDhawle / website / webpage'),


#STATICFILES_DIR = [os.path.join(BASE_DIR,'')]




web选项卡中静态文件集的链接是 -





我已经使用它了我的程序为 -




  {%load staticfiles%} 

< link rel =stylesheettype =text / csshref ={%static'pages / bootstrap.min.css'%}/>
< link rel =stylesheettype =text / csshref ={%static'pages / style.css'%}/>
<!DOCTYPE html>
< html lang =en>
< head>
< title> Dr.Chitra网页< / title>






错误日志在python任何地方是 -




  2015-03-08 16:09:52,766:django.core.exceptions.ImproperlyConfigured:SECRET_KEY设置不能空。 
2015-03-08 16:09:53,926:追溯(最近的电话最后):
2015-03-08 16:09:53,926:文件/bin/user_wsgi_wrapper.py,第130行,__call__
2015-03-08 16:09:53,926:self.error_log_file.logger.exception(运行WSGI应用程序时出错)
2015-03-08 16:09:53,926:文件 /usr/lib/python2.7/logging/__init__.py,第1185行,例外
2015-03-08 16:09:53,926:self.error(msg,* args,** kwargs)
2015-03-08 16:09:53,927:文件/usr/lib/python2.7/logging/__init__.py,第1178行错误
2015-03-08 16:09: 53,927:self._log(ERROR,msg,args,** kwargs)
2015-03-08 16:09:53,927:文件/usr/lib/python2.7/logging/__init__.py,行1270,在_log
2015-03-08 16:09:53,928:record = self.makeRecord(self.name,level,fn,lno,msg,args,exc_info,func,extra)
2015 -03-08 16:09:53,928:文件/usr/lib/python2.7/logging/__init__.py,第1244行,makeRecord
2015-03-08 16:09:53,928:rv = LogRecord(name,level,fn,lno,msg,arg s,exc_info,func)
2015-03-08 16:09:53,928:文件/usr/lib/python2.7/logging/__init__.py,第284行__init__
2015- 03-08 16:09:53,928:self.threadName = threading.current_thread()。name
2015-03-08 16:09:53,928:文件/usr/lib/python2.7/threading.py ,line 1160,in currentThread
2015-03-08 16:09:53,929:return _active [_get_ident()]
2015-03-08 16:09:53,929:文件/ bin / user_wsgi_wrapper。 py,第122行,__call__
2015-03-08 16:09:53,929:app_iterator = self.app(environ,start_response)
2015-03-08 16:09:53,929:文件 /bin/user_wsgi_wrapper.py,第136行,import_error_application
2015-03-08 16:09:53,929:raise e
2015-03-08 16:09:53,929:django.core.exceptions .ImproperlyConfigured:SECRET_KEY设置不能为空。




访问日志 -




  78.12.109.13  -   -  [09 / Mar / 2015:10:55:39 +0000]GET / static / chitraMam.jpg HTTP / 1.1404 1165http://drchitradhawle.pythonanywhere.com/Mozilla / 5.0(Windows NT 6.3; WOW64)AppleWebKit / 537.36(KHTML,像Gecko)Chrome / 41.0.2272.76 Safari / 537.36 78.12.109.13
78.12.109.13 - - [09 / Mar / 2015:10:55:40 +0000]GET /favicon.ico HTTP / 1.1404 1150 - Mozilla / 5.0 NT 6.3; WOW64)AppleWebKit / 537.36(KHTML,像Gecko)Chrome / 41.0.2272.76 Safari / 537.3678.12.109.13
78.12.109.13 - - [09 / Mar / 2015:10:55:43 + 0000]GET /static/webpage/bootstrap.min.css HTTP / 1.1404 1164http://drchitradhawle.pythonanywhere.com/Mozilla / 5.0(Windows NT 6.3; WOW64)AppleWebKit / 537.36(KHTML,like Gecko)Chrome / 41.0.2272.76 Safari / 537.3678.12.109.13
78.12.109.13 - - [09 / Mar / 2015:10:55:43 +0000]GET /static/webpage/style.css HTTP / 1.1404 1154http:// drch itradhawle.pythonanywhere.com/Mozilla / 5.0(Windows NT 6.3; WOW64)AppleWebKit / 537.36(KHTML,像Gecko)Chrome / 41.0.2272.76 Safari / 537.3678.12.109.13
78.12.109.13 - - [09 / Mar / 2015:10:55:56 +0000] GET / static HTTP / 1.1404 1148 - Mozilla / 5.0(Windows NT 6.3; WOW64)AppleWebKit / 537.36(KHTML,像Gecko)Chrome / 41.0.2272.76 Safari / 537.3678.12.109.13
78.12.109.13 - [09 / Mar / 2015:10:55:58 +0000]GET / static / HTTP / 1.1404 1149 - Mozilla / 5.0(Windows NT 6.3; WOW64)AppleWebKit / 537.36(KHTML ,像Gecko)Chrome / 41.0.2272.76 Safari / 537.3678.12.109.13
78.12.109.13 - - [09 / Mar / 2015:10:56:03 +0000]GET / static / /1.1404 1151 - Mozilla / 5.0(Windows NT 6.3; WOW64)AppleWebKit / 537.36(KHTML,像Gecko)Chrome / 41.0.2272.76 Safari / 537.3678.12.109.13
14.139.240.226 - - [09 / Mar / 2015:11:04:16 +0000]GET /网页/研究/ HTTP / 1.1200 1615http://drchitradhawle.pythonanywhere.com/Mozilla / 5.0(X11; Ubuntu; Linux x86_64; rv:38.0)Gecko / 20100101 Firefox / 38.014.139.240.226
14.139.240.226 - - [09 / Mar / 2015:11:04:17 +0000]GET /static/webpage/bootstrap.min.css HTTP / 1.1404 1164http://drchitradhawle.pythonanywhere.com/webpage/research/ Mozilla / 5.0(X11; Ubuntu的; Linux x86_64; rv:38.0)Gecko / 20100101 Firefox / 38.014.139.240.226
14.139.240.226 - - [09 / Mar / 2015:11:04:17 +0000]GET /static/webpage/style.css HTTP / 1.1404 1154http://drchitradhawle.pythonanywhere.com/webpage/research/Mozilla / 5.0(X11; Ubuntu; Linux x86_64; rv:38.0)Gecko / 20100101 Firefox / 38.014.139.240.226
14.139.240.226 - - [09 / Mar / 2015:11:04:18 +0000]GET /static/webpage/style.css HTTP / 1.1404 1154http://drchitradhawle.pythonanywhere.com /网页/研究/Mozilla / 5.0(X11; Ubuntu; Linux x86_64; rv:38.0)Gecko / 20100101 Firefox / 38.014.139.240.226
14.139.240.226 - - [09 / 11:04:18 +0000]GET /static/webpage/bootstrap.min.css HTTP / 1.1404 1164http://drchitradhawle.pythonanywhere.com/webpage/research/Mozilla / 5.0(X11; Ubuntu ; Linux x86_64; rv:38.0)Gecko / 20100101 Firefox / 38.014.139.240.226


解决方案

您的静态文件不起作用的原因是因为您的静态文件设置为 home / DrChitraDhawle / website /网页/ static 在webtab屏幕截图。它应该是 / home / DrChitraDhawle / website / pages / static



错误日志是旧的(即,你可能还没有产生任何新的错误,因为您最后一次修复旧的错误)


I have deployed a django(1.7) project in pythonanywhere and its link is- http://drchitradhawle.pythonanywhere.com/ I guess there is the problem with static file linking and bootstrap.Plz anybody help me to sort out the problem also tell me whole procedure to link any static file and bootstrap in a django project.

My project structure is -

home
    -DrChitraDhawle
              -website
                    -webpage
                        -static
                            -css
                            -images
                   -templates
                  -website
                 -settings.py

settings.py file is -

STATIC_ROOT = "/home/DrChitraDhawle/website/webpage/static"
STATIC_URL = '/static/'
STATICFILES_DIR = (
    ('assets', '/home/DrChitraDhawle/website/webpage'),
    )
#
#STATICFILES_DIR = [os.path.join(BASE_DIR, '')]

Link of static file set in web tab is -

And i have used it in my program as -

{% load staticfiles %}

<link rel="stylesheet" type="text/css" href="{% static 'webpage/bootstrap.min.css' %}" />
<link rel="stylesheet" type="text/css" href="{% static 'webpage/style.css' %}" />
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Dr.Chitra Webpage</title>
.
.
.

error log on python anywhere is -

2015-03-08 16:09:52,766 :django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
2015-03-08 16:09:53,926 :Traceback (most recent call last):
2015-03-08 16:09:53,926 :  File "/bin/user_wsgi_wrapper.py", line 130, in __call__
2015-03-08 16:09:53,926 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-03-08 16:09:53,926 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-03-08 16:09:53,926 :    self.error(msg, *args, **kwargs)
2015-03-08 16:09:53,927 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-03-08 16:09:53,927 :    self._log(ERROR, msg, args, **kwargs)
2015-03-08 16:09:53,927 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-03-08 16:09:53,928 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-03-08 16:09:53,928 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-03-08 16:09:53,928 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-03-08 16:09:53,928 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-03-08 16:09:53,928 :    self.threadName = threading.current_thread().name
2015-03-08 16:09:53,928 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-03-08 16:09:53,929 :    return _active[_get_ident()]
2015-03-08 16:09:53,929 :  File "/bin/user_wsgi_wrapper.py", line 122, in __call__
2015-03-08 16:09:53,929 :    app_iterator = self.app(environ, start_response)
2015-03-08 16:09:53,929 :  File "/bin/user_wsgi_wrapper.py", line 136, in import_error_application
2015-03-08 16:09:53,929 :    raise e
2015-03-08 16:09:53,929 :django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.

Access log -

78.12.109.13 - - [09/Mar/2015:10:55:39 +0000] "GET /static/webpage/images/chitraMam.jpg HTTP/1.1" 404 1165 "http://drchitradhawle.pythonanywhere.com/" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36" "78.12.109.13"
78.12.109.13 - - [09/Mar/2015:10:55:40 +0000] "GET /favicon.ico HTTP/1.1" 404 1150 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36" "78.12.109.13"
78.12.109.13 - - [09/Mar/2015:10:55:43 +0000] "GET /static/webpage/bootstrap.min.css HTTP/1.1" 404 1164 "http://drchitradhawle.pythonanywhere.com/" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36" "78.12.109.13"
78.12.109.13 - - [09/Mar/2015:10:55:43 +0000] "GET /static/webpage/style.css HTTP/1.1" 404 1154 "http://drchitradhawle.pythonanywhere.com/" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36" "78.12.109.13"
78.12.109.13 - - [09/Mar/2015:10:55:56 +0000] "GET /static HTTP/1.1" 404 1148 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36" "78.12.109.13"
78.12.109.13 - - [09/Mar/2015:10:55:58 +0000] "GET /static/ HTTP/1.1" 404 1149 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36" "78.12.109.13"
78.12.109.13 - - [09/Mar/2015:10:56:03 +0000] "GET /static/webpage/ HTTP/1.1" 404 1151 "-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36" "78.12.109.13"
14.139.240.226 - - [09/Mar/2015:11:04:16 +0000] "GET /webpage/research/ HTTP/1.1" 200 1615 "http://drchitradhawle.pythonanywhere.com/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" "14.139.240.226"
14.139.240.226 - - [09/Mar/2015:11:04:17 +0000] "GET /static/webpage/bootstrap.min.css HTTP/1.1" 404 1164 "http://drchitradhawle.pythonanywhere.com/webpage/research/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" "14.139.240.226"
14.139.240.226 - - [09/Mar/2015:11:04:17 +0000] "GET /static/webpage/style.css HTTP/1.1" 404 1154 "http://drchitradhawle.pythonanywhere.com/webpage/research/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" "14.139.240.226"
14.139.240.226 - - [09/Mar/2015:11:04:18 +0000] "GET /static/webpage/style.css HTTP/1.1" 404 1154 "http://drchitradhawle.pythonanywhere.com/webpage/research/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" "14.139.240.226"
14.139.240.226 - - [09/Mar/2015:11:04:18 +0000] "GET /static/webpage/bootstrap.min.css HTTP/1.1" 404 1164 "http://drchitradhawle.pythonanywhere.com/webpage/research/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" "14.139.240.226"

解决方案

The reason why your static files don't work is because your static files is set to home/DrChitraDhawle/website/webpage/static in the webtab screenshot. It should be /home/DrChitraDhawle/website/webpage/static

The error logs are old (ie. you probably have not generated any new errors since you've last fixed the old ones)

这篇关于在pythonanywhere中部署的django项目中链接静态文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆