我正在开发我的第一个django网站(基于探戈与django教程),并且在Debug = False时遇到了提供静态文件的问题。 (当我有Debug = True时一切运行良好)
我的文件夹结构如下:
|___401.shtml
|___500.shtml
|___requirements.txt
|___400.shtml
|___populate_rango.py
|___manage.py
|___templates
| |___rango
| | |___index.html
| | |___category.html
| | |___cats.html
| | |___category_list.html
| | |___add_category.html
| | |___base.html
| | |___register.html
| | |___restricted.html
| | |___about.html
| | |___login.html
| | |___add_page.html
| |___registration
| | |___logout.html
| | |___registration_complete.html
| | |___registration_form.html
| | |___login.html
|___media
| |___photo.png
| |___.htaccess
| |___profile_images
| | |___Screenshot_from_2016-07-18_145936.png
| | |___Screenshot_from_2016-07-21_112910.png
|___cgi-bin
| |___.htaccess
|___rango
| |___admin.py
| |___migrations
| | |___0003_category_slug.py
| | |_____init__.pyc
| | |___0003_category_slug.pyc
| | |___0001_initial.pyc
| | |___0001_initial.py
| | |___0004_userprofile.pyc
| | |___0002_auto_20160804_1857.py
| | |___0002_auto_20160804_1857.pyc
| | |___0004_userprofile.py
| | |_____init__.py
| |___models.py
| |___tests.py
| |_____init__.pyc
| |___models.pyc
| |___templatetags
| | |_____init__.pyc
| | |___rango_extras.pyc
| | |___rango_extras.py
| | |_____init__.py
| |___forms.py
| |___views.pyc
| |___urls.py
| |___admin.pyc
| |___views.py
| |___urls.pyc
| |___forms.pyc
| |_____init__.py
|___tango_with_django_project
| |___settings.pyc
| |___wsgi.pyc
| |_____init__.pyc
| |___urls.py
| |___settings.py
| |___urls.pyc
| |___wsgi.py
| |_____init__.py
|___static
| |___images
| | |___photo.png
| | |___rango.png
| |___.htaccess
| |___js
| | |___rango-jquery.js
| | |___jquery.js
| | |___rango-ajax.js
|___db.sqlite3
|___test.py
|___404.shtml
|___403.shtml
我在settings.py路径中添加了STATIC_ROOT,如下所示:
import os
import uwsgi
from uwsgidecorators import timer
from django.utils import autoreload
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
(...)
ROOT_URLCONF = 'tango_with_django_project.urls'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
STATIC_ROOT,
)
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'static')
现在我想从ssh终端运行
python manage.py collectstatic
但是我面临一个错误
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/home/mrklap/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/mrklap/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
settings.INSTALLED_APPS
File "/home/mrklap/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
self._setup(name)
File "/home/mrklap/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/home/mrklap/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 98, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'tango_with_django_project.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named uwsgi
我在这里阅读帖子和schwärzl回答:
ImportError: Could not import settings
并将wsgi.py文件修改为:
import os
import sys
sys.path.append('home/mrklap/domains/tredo.net/public_html/tango_with_django_project')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tango_with_django_project.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
但是当我在ssh中运行(或运行)virtualenv并运行时:
>>> import sys
>>> for path in sys.path: print path
...
我没有获得添加路径
/home/mrklap/venv/lib/python2.7
/home/mrklap/venv/lib/python2.7/plat-x86_64-linux-gnu
/home/mrklap/venv/lib/python2.7/lib-tk
/home/mrklap/venv/lib/python2.7/lib-old
/home/mrklap/venv/lib/python2.7/lib-dynload
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/home/mrklap/venv/local/lib/python2.7/site-packages
/home/mrklap/venv/lib/python2.7/site-packages
>>>
为什么我在下面的列表中看不到这条路径?
答案 0 :(得分:2)
尝试sudo pip install uwsgi
正如您在设置文件中导入它