Static content in Django - python

I am trying to load the static content for my Django which I have upgraded to Django 1.4
The project has been successfuly deployed , but I am unable to find the images and all the static content of the project.
Please find the settings.py file
# Django settings for DataEntry project.
import sys
import os
from path import path
SETTINGS_FILE_FOLDER = path(__file__).parent.abspath()
sys.path.append(SETTINGS_FILE_FOLDER.joinpath("libs").abspath())
DEBUG = True
TEMPLATE_DEBUG = DEBUG
INTERNAL_IPS = ("127.0.0.1", "localhost", "192.168.100.102")
ADMINS = (
(" Hello World ", "hello.world#gmail.com"),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'gototest', # Or path to database file if using sqlite3.
'USER': 'root', # Not used with sqlite3.
'PASSWORD': 'root', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
'OPTIONS': {
"init_command": "SET storage_engine=INNODB",
}
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'Asia/Calcutta'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
#MEDIA_ROOT = os.path.join(SETTINGS_FILE_FOLDER,'static')
MEDIA_ROOT = '/static'
STATIC_PATH = '/static'
UPLOAD_DIR = '/Users/iceman/Documents/gototest/qbank/static/uploads'
SITE_NAME = 'demo.com'
SITE_URL = 'http://alphadev.demo.com'
AUTH_PROFILE_MODULE = 'core.UserProfile'
LOGIN_REDIRECT_URL = '/students/login/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''
#STATIC_ROOT = '/Users/iceman/Documents/gototest/qbank/static'
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = ' hidden '
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
# 'django.template.loaders.filesystem.load_template_source',
# 'django.template.loaders.app_directories.load_template_source',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.gzip.GZipMiddleware',
#'utils.XhtmlMortifierMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
SESSION_ENGINE = 'django.contrib.sessions.backends.cached_db'
#simplCACHE_BACKEND = 'memcached://127.0.0.1:11211/'
ROOT_URLCONF = 'urls'
TEMPLATE_DIRS = (
SETTINGS_FILE_FOLDER.joinpath("../templates"),
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
TEMPLATE_LOADERS = (
#'django.template.loaders.filesystem.load_template_source',
#'django.template.loaders.app_directories.load_template_source',
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
AUTHENTICATION_BACKENDS = (
'accounts.backends.EmailOrUsernameModelBackend',
'django.contrib.auth.backends.ModelBackend'
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.sites',
'django.contrib.flatpages',
'core',
'tinymce',
'filebrowser',
'tagging',
'tagging_autocomplete',
'django_extensions',
'registration',
'questionmanager',
'corporate',
)
ADMIN_HASH_SECRET = " "
RECAPTCHA_PUBLIC_KEY = " "
RECAPTCHA_PRIVATE_KEY = " "
SERIALIZATION_MODULES = { 'modeljson' : 'wadofstuff.django.serializers.json' }
SOLR_ROOT = "http://dev.demo.com:8080/QuestionSolr"
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.request",
"django.core.context_processors.i18n",
"utils.context_processor",
"qutils.context_processor",
)
#'plugins': "table,paste,searchreplace,safari,asciimath,contextmenu",
TINYMCE_JS_URL = "/static/tinymce/tiny_mce/tiny_mce.js"
TINYMCE_JS_ROOT ="/static/tinymce/tiny_mce"
TINYMCE_DEFAULT_CONFIG = {
'plugins': "table,asciimath,gototest,indicime",
'mode' : "textareas",
'theme': "advanced",
'cleanup_on_startup': True,
'custom_undo_redo_levels': 10,
'theme_advanced_buttons1' : "fontselect,fontsizeselect,formatselect,bold,italic,underline,strikethrough,separator,sub,sup,separator,cut,copy,paste,undo,redo",
'theme_advanced_buttons2' : "justifyleft,justifycenter,justifyright,justifyfull,separator,numlist,bullist,outdent,indent,separator,forecolor",
'theme_advanced_buttons3' : "gototest,backcolor,separator,hr,link,unlink,image,table,code,separator,asciimath,asciimathcharmap,indicime",
'theme_advanced_fonts' : "Arial=arial,helvetica,sans-serif,Courier New=courier new,courier,monospace,Georgia=georgia,times new roman,times,serif,Tahoma=tahoma,arial,helvetica,sans-serif,Times=times new roman,times,serif,Verdana=verdana,arial,helvetica,sans-serif",
'theme_advanced_toolbar_location' : "top",
'theme_advanced_toolbar_align' : "left",
'theme_advanced_statusbar_location' : "bottom",
'tab_focus' : ':prev,:next',
}
#'content_css' : "/static/css/content.css",
TINYMCE_SPELLCHECKER = False
TINYMCE_COMPRESSOR = True
FORCE_LOWERCASE_TAGS = True
MARKITUP_FILTER = ('markdown.markdown', {'safe_mode': True})
MARKITUP_SET = 'markitup/sets/markdown'
MARKITUP_SKIN = 'markitup/skins/markitup'
MARKITUP_MEDIA_URL = '/static/'
MARKITUP_AUTO_PREVIEW = True
JQUERY_URL = '/static/js/jquery-1.3.2.min.js'
TAGGING_AUTOCOMPLETE_JS_BASE_URL = "/static"
try:
from local_settings import *
except ImportError: pass
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
When I am looking for the images on the browser URL = http://127.0.0.1:8000/static/site_img/logo.gif
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/static/site_img/logo.gif
"/Users/iceman/Documents/gototest/qbank/qbank/static/site_img/logo.gif" does not exist

To anwer your specific problem, i thing your STATICFILES_DIRS key is missing.
This appear to be your debug config file, so I suppose you want to serve your files with django built-in developement web server (ie: doing "manage.py runserver 8000")
1. DEBUG=True|False
You must know that django should not be used to serve files in production and will refuse to do so.
If you have "DEBUG=False", django will refuse to serve static files by default.
You have to use another server (most people use nginx, or an online cloud service, like cloudfront for this)
For this there is a 2 step process
1. You need to collect static files
2. Set up another server to serve them
When developping this is not convenient, so django look into STATICFILES_DIRS for you, and serve static files
2. Collecting files
A django website is made of multiple applications (see "INSTALLED_APPS" key in your config).
Each one of them may declare static files, all in different directories in your filesystem.
For your files to be properly served, you need them to be grouped in a single local directory, or a single remote server, hence the "./manage.py collectstatic".
This command will scan every directory listed in STATICFILES_DIRS and every "static" directory in loaded applications, and then copy files to the place you want with STATICFILES_STORAGE and STATIC_ROOT)
3. Config keys
# Tells django where your static files are
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), '../static/generated'),
os.path.join(os.path.dirname(__file__), '../static/fixed'),
)
# Only for developpement
# Tells to django build in web server where to host your files ("http://localhost/static")
STATIC_URL = '/static/'
# for production, tell django how do {% static %} template tags and "./manage collectstatic" behave (collect files to a single directory, upload them to a CDN, etc)
#
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
# Only for production when using default value for STATICFILES_STORAGE
# Tell django where to collect files when you run "./manage.py collectstatic".
# This is only used if you host your static files in the same machine as the rest of your application
STATIC_ROOT = '/var/www/static.mydomain.com/'

Try to add STATICFILES_FINDERS and STATICFILES_STORAGE (for deployment) to your settings file.
This will make your life much easier in Django: you put a static folder in each of your apps for when you develop, and when you deploy, you run the collect_static command on your project and all the statics from all the apps will be gathered in the folder specified in the STATICFILES_STORAGE settings.
In the deployment environment, the STATICFILES_STORAGE should be served by the web server.

Related

Gunicorn cannot find system Renviron error

I have been struggling with this for days, reaching my limit.
I am porting a Django project from using mod_wsgi/httpd to use gunicorn/nginx
I have set up a virtual environment using virtualenv/virtualenvwrapper and pip installed the requirements file into it, as well a gunicorn. The django project is a very complex site with lots of dependencies.
When I start the app using
`python manage.py runserver`
everything runs fine with no errors. However when I try to start with gunicorn
`gunicorn wsgi`
I get this error
```
cannot find system Renviron
Fatal error: unable to open base package
```
I don't even know where to start troubleshooting this. I have added .Renviron files to my user directory, added os.environ["Renviron"]=/path to both the wsgi.py and settings.py files, downgraded RPy2 back to 2.5.6. Nothing seems to help. I don't know what else to do. Any help would be much appreciated.
Here is my set up:
MacOS High Sierra (10.13.5) running in Parallels Desktop Lite 1.3.3 VM
Django==1.9.2
gunicorn=19.9.0
gevent==1.3.4
greenlet==0.4.13
whitenoise==3.3.1
rpy2==2.5.6
Homebrew==1.6.17
R=3.5.1
Django wsgi.py file
"""
WSGI config for ri project.
"""
import os, sys, socket, site
dev_path = "/Users/evans/.virtualenvs/base_env/"
os.environ["R_HOME"]='/usr/local/lib/R/etc/Renviron'
os.environ["Renviron"]='/usr/local/lib/R/etc/Renviron'
host = socket.gethostname()
print "HOST: ",host
site.addsitedir(dev_path+'lib/python2.7/site-packages')
# Activate the virtual environment
# Taken from http://thecodeship.com/deployment/deploy-django-apache-virtualenv-and-mod_wsgi/
activate_env = os.path.expanduser(dev_path+'bin/activate_this.py')
execfile(activate_env, dict(__file__=activate_env))
sys.path.insert(0,'/usr/local/var/django/code')
sys.path.insert(0,'/usr/local/var/django/code/ri')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ri.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Django settings.py file
# Django settings for ri project.
import socket
import sys
import os
os.environ["Renviron"]="/usr/local/lib/R/etc/Renviron"
Renviron="/usr/local/lib/R/etc/Renviron"
R_HOME="/usr/local/lib/R/etc/Renviron"
host = socket.gethostname()
BASE_PATH="/usr/local/var/django/code"
DEBUG = True # will not send email if True, Runserver will not serve static files if False
if DEBUG:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
ADMINS = (('Mark Evans',),)
MANAGERS = ADMINS
TESTING = 'test' in sys.argv
# explicitly naming this is asked for in django > 1.6
TEST_RUNNER = 'django.test.runner.DiscoverRunner'
DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2',
# Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'foodb', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'fooadmin',
'PASSWORD': 'foo_admin',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
},
}
if TESTING:
DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'test_db', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': 'foo',
'PASSWORD': 'foo_admin',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
# Test runner with no database creation
TEST_RUNNER = 'ri.RiTestRunner.RiTestRunner'
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = ['localhost']
TIME_ZONE = 'America/Los_Angeles'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
USE_I18N = False
USE_L10N = True
USE_TZ = False
ROOT_URLCONF = 'ri.urls'
SETTINGS_FILE_FOLDER = BASE_PATH + '/ri'
#default login redirect path
LOGIN_REDIRECT_URL = '/'
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = BASE_PATH + '/media'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = BASE_PATH + '/static/'
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = ( BASE_PATH + '/static_src/',)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder')
ADMIN_MEDIA_PREFIX = '/static/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'xxxxxxxxxxxxxxxxx'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ BASE_PATH+"/ri/templates",],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
],
},
},
]
MIDDLEWARE_CLASSES = (
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'debug_panel.middleware.DebugPanelMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
# the following class logs out a user after AUTO_LOGOUT_DELAY amount of time
'ri.middleware.AutoLogout',
)
# Add automatic caching and compression support
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
},
# this cache backend will be used by django-debug-panel
'debug-panel': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/debug-panel-cache',
'OPTIONS': {
'MAX_ENTRIES': 200
}
}
}
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'ri.wsgi.application'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'django.contrib.postgres',
'debug_toolbar',
'debug_panel',
# Put RI apps below this line in alphabetical order
'ri', # in order to access project, target, etc
)
Update - So I was never able to actually find a solution to the problem per se. However I was able to isolate it by commenting out the apps in the INSTALLED_APPS section of settings.py until I found the app that was responsible for the R dependency. Turns out I didn't need it, so I removed that app and now things work.
Still an odd situation though.
The value of R_HOME does not look right. It should be the name of a directory, like "/usr/local/lib/R", not a file.
That said, R may start up just fine by itself, but appears prone to this issue (cannot find system Renviron) when you try to use it from another language, be it Python, Java, or Tcl. It may require the R_HOME environment variable, which it normally doesn't need.

Directory indexes not allowed here Django

I have a django app. Here is my directory structure.
.
+--media
+--index.html
+--static
+--extjs
+--<extjs files>
+--updater
+--app
+--images
+--ux
+--app.js
+--index.html
+--index.html
+--templates
+--<template files>
+--uapp
+--__init__.py
+--models.py
+-- <etc>
+--manage.py
+--settings.py
+--urls.py
here is my settings.py
import os
# Django settings for uproject project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#domain.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'updates', # Or path to database file if using sqlite3.
'USER': '<user>', # Not used with sqlite3.
'PASSWORD': '<password>', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Los_Angeles'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Path to project installation.
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
#MEDIA_ROOT = os.path.join(SITE_ROOT, 'static')
MEDIA_ROOT = os.path.join(SITE_ROOT, 'media')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/updater/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = os.path.join(SITE_ROOT, 'static')
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = "/static/"
# Additional locations of static files
STATICFILES_DIRS = (
#os.path.join(SITE_ROOT, 'static'),
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'hnu51442$##gdsvx5v!61w^4-vjevy8xm6tqb56#bc216!nw-nl-%'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.gzip.GZipMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'urls'
# WSGI_APPLICATION = 'wsgi.application'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(SITE_ROOT, 'templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'haystack',
'uapp',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(os.path.dirname(__file__), 'whoosh_index'),
},
}
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
LOGIN_URL = '/updater/uapp/login/'
LOGOUT_URL = '/updater/uapp/logout/'
LOGIN_REDIRECT_URL = '/updater/media/updater/'
CACHE_BACKEND = 'db://listclient_cache'
When I go to localhost:8000/static/updater/ I get Directory Indexes not allowed here error.
Any idea? I think there is some error in the way static files are being served. I am using extjs by the way.
I am expecting the index.html in static/updater/ directory to show up. Does it happen by default?
It seems that for some reason Django doesn't want to serve the directory listing of /static/updater/. Because static updater is a directory, not a file, try doing /static/updater/index.html or just /static/index.html and see if either are served. If they are not served, it may be an issue with your static files setup. If so, then I am not sure if it's just Django refusing to serve directory indexes within static folders or something else.
(This feels like it should be a comment, but I don't have enough rep to comment.)
Your STATICFILES_DIRS is empty - the dev server will serve from here.
You must edit your urls.py and add these lines to it then go to django.views.static.serve and change show_indexes argument to True.
Addition of urls.py:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
#import this at top
url(r'^static/(?P<path>.*)$', 'django.views.static.serve',{'document_root':"path\to\your\static\folder"}),
#add this to urlpatterns variable
urlpatterns += staticfiles_urlpatterns()
#add this in last line of urls.py
Now you are finished and django shows indexes
if you want to change the html view of it you must follow instructions in django.views.static.serve and add your favourite html file to static/directory_index.html
In addition to henrikstroem's answer:
You should have a look at the official documentation on STATIC_ROOT and STATICFILES_DIRS.
Basically, STATIC_ROOT is the location where the collectstatic command will collect all the static files to, and STATICFILES_DIRS is the location (or are the locations) where that command will look for static files.
My development setup looks like this:
project_root
+ apps
+ project
__init__.py
settings.py
urls.py
wsgi.py
+ run
dev.sqlite3
+ media
+ static
+ static
+ templates
I point STATIC_ROOT to project_root/run/static and include project_root/static in STATICFILES_DIRS.
As you can see, I store my static assets in project_root/static and they get served.
During development (meaning: while using the runserver command), your static assets will be served directly from their location, in my case project_root/static. When deploying, you will collect your static assets to STATIC_ROOT.
This can be a folder in your project (as my project_root/run/static or even a directory in a totally other environment, you may even copy them over to a CDN [Content Delivery Network]).
Personally, I like deploying with Apache. I will setup one virtualenv to handle the Django parts. Static assets are served by another virtualenv which totally bypasses all dynamic handling and simply serves static files. You could even use another server, like nginx, for this task.
In shameless self-advertising, you can fetch my project skeleton here.

Finding django version number for an old project

I'm starting on a project that someone began >2 years ago and I'm having trouble figuring out what version of django it runs. The person who made the project doesn't know, and I'm not sure guessing and checking would work, since I don't actually know that the project compiles. I've found this answer, but it suggests that the version is pre-1.0, and I'm not really sure where to go from there. Is there a good way of telling what the version is, besides guessing and checking?
My settings.py is
import os
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#domain.com'),
)
MANAGERS = ADMINS
DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = os.path.join(PROJECT_PATH, 'site.db') # Or path to database file if using sqlite3.
DATABASE_USER = '' # Not used with sqlite3.
DATABASE_PASSWORD = '' # Not used with sqlite3.
DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = '' # Set to empty string for default. Not used with sqlite3.
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = ''
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/admin/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = some gibberish
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
)
#ROOT_URLCONF = 'site.urls'
ROOT_URLCONF = 'project.urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'project.site',
)
#TD_SERVER_PORT = 'tcp:8080:interface=192.168.1.43'
#TD_BIN_DIR = '/Users/me/django/project/bin'
TD_WORK_DIR = '/Users/me/td_work'
TD_COMPACT_MODE = False
TD_MAX_UPLOAD_RATE = 20 * 1024
TD_MAX_DOWNLOAD_RATE = 80 * 1024
#TD_LISTEN_PORT_MIN = 59543
#TD_LISTEN_PORT_MAX = 59553
TD_LISTEN_PORT_MIN = 6881
TD_LISTEN_PORT_MAX = 6891
# Icecast stream upload settings.
TD_STREAM_NAME = '[o_o] site.net'
TD_STREAM_PORT = 8000
#TD_STREAM_HOST = 'thingie.com'
#TD_STREAM_PASSWORD = 'poiuyt'
TD_STREAM_HOST = 'localhost'
TD_STREAM_PASSWORD = 'qwerty'
#TD_STREAM_HOST = 'otherthingie.com'
#TD_STREAM_PASSWORD = 'wopwopwop'
# CD Ripper
TD_CD_DIR = '/home/me/td_work/cds'
My manage.py is
#!/usr/bin/env python
from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)
My urls.py is
from django.conf.urls.defaults import *
from project.site.models import Syndicator, Torrent
torrent = {
'queryset': Torrent.objects.all(),
'extra_context': {'syndicators': Syndicator.objects.all()},
}
torrents = {
'queryset': Torrent.objects.all().order_by('-pub_date'),
'paginate_by': 25,
'allow_empty': True,
'extra_context': {'syndicators': Syndicator.objects.all()},
}
urlpatterns = patterns('',
(r'^$', 'django.views.generic.list_detail.object_list', torrents, 'home-page'),
(r'^feeds/$', 'django.views.generic.list_detail.object_list', torrents, 'feed-list'),
(r'^feeds/page(?P<page>[0-9]+)/$', 'django.views.generic.list_detail.object_list', torrents, 'feed-list-page'),
(r'^feeds/post/(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', torrent, 'feed-post'),
(and a lot more patterns),
)
(virtualenv)~$ python
>>> import django
>>> print django.get_version()
'1.4.1'
I'm not sure it matters exactly. The database settings imply pre-1.2, so 1.1 should work fine. Django very rarely breaks backwards compatibility (that database one is a rare exception) so differences between point versions shouldn't have much impact.

Errors 404 and 500 while access static files in Django [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I tried to use static files in Django. When I access files directly (by ../static/1.txt), it gives me Error 404 or Error 500 (depends on what Stackoverflow answer I follow)
The code in the Settings.py is the following:
# Django settings for mysite project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '', # Set to empty string for default.
}
}
# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# In a Windows environment this must be set to your system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
USE_L10N = True
# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
import os
settings_dir = os.path.dirname(__file__)
PROJECT_ROOT = os.path.abspath(os.path.dirname(settings_dir))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = 'C:/Python27/Lib/site-packages/django/mysite/mysite/static/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
# "C:/Python27/Lib/site-packages/django/mysite/mysite/static",
os.path.join(PROJECT_ROOT, 'static/mysite/'),
PROJECT_ROOT + '/static/'
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '***'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'mysite.wsgi.application'
import os.path
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(os.path.dirname(__file__), 'templates/mysite').replace('\\','/'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error when DEBUG=False.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
What's wrong with this settings file?
Why can't I access static files in my directory "static/mysite"?
And here is the link to the source code of the app I think that I may be missing something very simple...
In your settings.py, define the STATIC_ and MEDIA_ values:
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/path/to/mydjangosite/media/'
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = 'http://www.mydjangosite.com/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/path/to/mydjangosite/static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = 'http://www.mydjangosite.com/static/'
Also, ensure that the correct STATICFILES_FINDERS are configured:
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
The AppDirectoriesFinder must be enabled to collect static files from the static/ sub-directory within each app. Additionally, ensure that your apps are included in the INSTALLED_APPS setting or else the AppDirectoriesFinder won't know where to look for static files:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
# DJANGO SOUTH
'south',
# MY APPS
'my_django_app',
)
Then, to collect static from the various app folders (e.g. my_project/my_app/static) you must invoke the manage.py command collectstatic:
python manage.py collectstatic
This moves all the various apps' static files into the folder specified by STATIC_ROOT in settings.py.
Finally, ensure that your static folder is served directly by your web server and not via the Django WSGI application. For Apache2 /etc/apache2/sites-available/my_django_site.conf:
<VirtualHost *:80>
ServerName www.mydjangosite.com
ServerAlias mydjangosite.com
ServerAdmin fake#mydjangosite.com
DocumentRoot /path/to/mydjangosite
<Directory /path/to/mydjangosite>
Options FollowSymLinks
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /static/ /path/to/mydjangosite/static/
<Directory /path/to/mydjangosite/static>
Order allow,deny
allow from all
</Directory>
Alias /media/ /path/to/mydjangosite/media/
<Directory /path/to/mydjangosite/media>
Order allow,deny
allow from all
</Directory>
# The following installs the Django WSGI app
WSGIDaemonProcess www.mydjangosite.com processes=2 threads=15 display-name=%{GROUP}
WSGIProcessGroup www.mydjangosite.com
WSGIScriptAlias / /path/to/mydjangosite/wsgi.py
</VirtualHost>
An explicit Alias definition and a Directory tag for the alias'd directory will override any WSGI application running in a higher-level parent directory.
Execute sudo service apache2 restart to load the new site.conf configuration.
Staticfiles in Django is one of the more confusing parts of the framework in my opinion. Django expects you to put static files into a folder that will be served locally during development, but collected to another directory, along with any other static media 3rd party app modules might be using, in production as a result of running manage.py collectstatic
Here is the directory structure that I use, and a helper function to make life a little easier in regards to static files...
# A Sample Project structure
/sample_app
manage.py
/sample_app
# this directory is served by the 'staticfiles' app during development
# as specified by STATICFILES_DIRS for the location of the files
# and a STATIC_URL of '/static/'
/static-assets/
/css
/js
/images
# this directory is where all of the folders and files specified in the
# STATICFILES_DIRS setting get collected to for deployment. The files
# will be collected to the directory specified by the STATIC_ROOT setting.
/static
# settings.py
import os
# a helper function to return absolute paths, using settings.py
# as a starting point. This assumes Django >= 1.4.x
def map_path(directory_name):
return os.path.join(os.path.dirname(__file__),
'../' + directory_name).replace('\\', '/')
MEDIA_ROOT = map_path('static/uploads/')
MEDIA_URL = '/static/uploads/'
STATIC_ROOT = map_path('static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
map_path('static-assets'),
)
# You can also use map_path for other paths, like templates
TEMPLATE_DIRS = (
map_path('templates),
)
TEMPLATE_CONTEXT_PROCESSORS = (
...
'django.core.context_processors.request',
'django.core.context_processors.static'
...
)
Then you should be able to reference static files in your templates as:
<link type="text/css" rel="stylesheet"
href="{{ STATIC_URL }}css/base.css" media="screen,projection" />
Another potential gotcha is that the staticfiles app only works when DEBUG = True

django unable to open database file

i am implementing a django web site,
the site goes to the hello world view:
http://ec2-107-20-20-19.compute-1.amazonaws.com/
views.py /home/ubuntu/djangoProj/micopiloto/portfolio
# Create your views here.
from django.http import HttpResponse
def view(request):
return HttpResponse('Hello Worlsss9d!')
but i cannot see the amin site, I see this error: unable to open database file
> http://ec2-107-20-20-19.compute-1.amazonaws.com/admin/
settings.py `/home/ubuntu/djangoProj/micopiloto`
# Django settings for micopiloto project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'thadb.db', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# URL prefix for admin static files -- CSS, JavaScript and images.
# Make sure to use a trailing slash.
# Examples: "http://foo.com/static/admin/", "/static/admin/".
ADMIN_MEDIA_PREFIX = '/static/admin/'
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '2&g_&k=+^(0t)1xf82m^=#0u6v1e!)nn7ixq*+2^h%4$mwlrsm'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'micopiloto.urls'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'portfolio'
)
# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
# the site admins on every HTTP 500 error.
# See http://docs.djangoproject.com/en/dev/topics/logging for
# more details on how to customize your logging configuration.
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler'
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
}
so i see the created thadb.db
in my project folder,
i have the error:
Exception Value:
unable to open database file
so I have $sudo chmod 777 thadb.db
but still get the same error,
is this because of the permission?
should i set the folder to 777?
EDIT>>
As per suggested solution, i tried chmod root for the db and the root folder
-rwxrwxrwx 1 root ubuntu 44032 2012-04-09 09:49 thadb.db
drwxrwxrwx 3 root ubuntu 4096 2012-04-09 12:44 micopiloto
Still not working! ;(
i get this error:
Exception Value:
unable to open database file
So how to make the admin show??
how will the security be affected?
thanks!
Here is an article that describes a solution to your problem:
http://www.pantz.org/software/sqlite/unabletoopendbsqliteerror.html
The solution is to make sure the directory containing the database file also has write access allowed to the process.
Also, Django has a page for this problem.
https://code.djangoproject.com/wiki/NewbieMistakes#DjangosaysUnabletoOpenDatabaseFilewhenusingSQLite3
ok, after much grappling got it to worked, so if another noob haves this problem this is part of the solution[ with making the db file n folder for the db with the right permissions]
the problem was the path for my db on the settings.py
i gave the whole path and then it worked ;)
/home/ubuntu/djangoProj/micopiloto/
thanks!
https://stackoverflow.com/a/10071711/11124205
works for me. Try to let www-data write in database directory to let sqlite create the journal file.

Categories