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.
Related
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.
My project tree in home/DjangoProjects/django_bookmarks/env/django_bookmarks looks like:
django_bookmarks/ #project
django_bookmarks/
__init__.py
settings.py
urls.py
wsgi.py
bookmarks/ #made with python manage.py startapp bookmarks
__init__.py
models.py
test.py
views.py
manage.py
In ../bookmarks/views have:
from django.http import HTTPResponse
def main_page(request):
output = '''
<html>
<head><title>%s</title></head>
<body>
<h1>%s</h1><p>%s</p>
</body>
</html>
''' % (
'Django Bookmarks',
'Welcome to Django Bookmarks',
'Where you can store and share bookmarks!'
)
return HttpResponse(output)
In .../django_bookmarks/urls have:
from django.conf.urls import patterns, include, url
from bookmarks.views import main_page # Unresolved import: main_page
# from bookmarks.views import * # Undefined variable: main_page in line below
...
urlpatterns = patterns('',
(r'^$', main_page)
)
EDIT:
In ../django_bookmarks/settings:
# Django settings for django_bookmarks 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', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '/home/novak/DjangoProjects/django_bookmarks/env/django_bookmarks/django_bookmarks/sqlite.db', # 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/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/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.
)
# 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 = '0i_*)b7)hc0oy^7qyit47w%k65pwfo7e#p)k=7lho3)q5!mx+!'
# 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 = 'django_bookmarks.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'django_bookmarks.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.
)
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,
},
}
}
In ../django_bookmarks/wsgi:
"""
WSGI config for django_bookmarks project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "django_bookmarks.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_bookmarks.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
Django version is 1.5.1.
When I run the project (ctrl+F11) there is no error in console, just in-line error markers in Eclipse text editor. Eclipse apparently somehow runs previous version of code that works and in browser shows this previous version ignoring this error.
Earlier this same code was works well (this is code from the book) and therefore I think problem are some settings in Eclipse or eventually something in the way I created this project.
I was created project on this way http://blog.bixly.com/post/25093181934/setting-up-eclipse-for-python-django-development
I read here that people had problems with importing modules and mostly it was because the lack of init.py in app directory or some issue with PYTHONPATH settings. What I read did not help me to solve my problem.
*I'm a begginer in Django and this is the first time I write Django. This is an example from the book "Learning Website Development with Django", Ayman Hourieh.
You need to inform the Python interpreter to look one directory above.
Try a relative path import
from ..bookmarks.views import main_page
The '..' says to look a directory above to find the bookmarks package.
May I suggest to you a more robust pattern to accomplish this?
django_bookmarks/ #project
django_bookmarks/
__init__.py
settings.py
urls.py
wsgi.py
bookmarks/ #made with python manage.py startapp bookmarks
__init__.py
models.py
test.py
views.py
urls.py # ADD another urls.py to your bookmarks app
manage.py
In django_bookmarks/urls.py
from django.conf.urls import patterns, include, url
# from bookmarks.views import main_page # Remove this
# This directs Django to the urls.py within the bookmarks app
urlpatterns = patterns('',
(r'^$', include('bookmarks.urls'))
)
In bookmarks/urls.py
from django.conf.urls import patterns, include, url
from bookmarks import views
# This directs Django to the urls.py within the bookmarks app
urlpatterns = patterns('',
(r'^$', views.main_page)
# Now you can add more bookmark urls to match to bookmark views
)
This pattern is more maintainable and allows all the bookmark url patterns to live inside bookmarks/urls.py.
OK,looks like I solved this problem.
Issue was in the way I made this Django project in Eclipse.
I was used python virtualenv which makes a little enviroment with its own env/bin/python2.7 interpreter and this interpreter supposed to be selected in creating project dialog.
This Python have no Django preinstalled (of course), you have to install it if you want it.
I created this project in my env/ made with virtualenv but leave interpreter settings on "Default" so PyDev was using python interpreter from system not env/bin/python2.7 and could not found env/django_bookmarks/bookmarks app on his PYTHONPATH which caused ImportError.
Conclusion is actually logical, if you make Django project in virtual enviroment you use python interpreter from virtual enviroment.
Thank you Paul Renton for your time.
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.
I already searched for everything I could, but this annoying error is still there. The admin interface (localhost:8000/admin/) works fine, but no one else. Obs.: Im using Apress - Practical Django Projects (2nd edition) to learn Django. I'll post my code here so somebody can tell what I did wrong. Thanks!
Code:
settings.py
# Django settings for cms project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
APPEND_SLASH = True
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'C:\Users\Vinicius\Desktop\Work\Djangoprojects\cms\cms.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
# 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: "/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/'
# 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 = 'notgiven'
# 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',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'cms.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'cms.wsgi.application'
TEMPLATE_DIRS = (
'C:/Users/Vinicius/Desktop/Work/Djangoprojects/cms/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.
)
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.flatpages',
# 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,
},
}
}
urls.py
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'', include('django.contrib.flatpages.urls')),
)
PS: Everything is idented correctly. So if there are some identation mistakes, it's because I did the copy/paste real quick.
You should not include flatpages in your url conf.
url(r'^admin/', include(admin.site.urls)),
url(r'', include('django.contrib.flatpages.urls')), # remove this
That's probably why you're getting the error... as flatpages practically match any URL.
Normally flatpages work via the flatpage fallback middleware that will attempt to locate a flatpage IF no other urls match.
Another cause of problem is not putting the correct SITE_ID number in settings.py
You can find the correct site id for 127.0.0.1:8000 (assuming you use the default port) by inspecting the table django_flatpage_sites in your database. The site id will be found in the column site_id.
Updating the SITE_ID to that number in settings.py , solved the issue for me.
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.