I am developing my first django website (based on tango with django tutorial), and faced problem with serving static files when Debug = False. (When I had Debug = True everything worked well)
my folders structure is as following:
|___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
i added STATIC_ROOT in settings.py path as follows:
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')
and now i want to run from ssh terminal
python manage.py collectstatic
however i am facing an error
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
i read post and schwärzl answer here:
ImportError: Could not import settings
and modified wsgi.py file to:
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()
but still when i am in (or out) virtualenv in ssh and run:
>>> import sys
>>> for path in sys.path: print path
...
i am not getting added 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
>>>
why i can't see that path in listing below?