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.
Related
wget https://bitbucket.org/slav0nic/djangobb_project/get/tip.tar.gz
tar zxvf tip.tar.gz
cd slav0nic-djangobb_project-tip/
pip install -r requirements.txt
cd basic_project/
touch local_settings.py
#set DATABASE
./manage.py syncdb --all
./manage.py collectstatic
./manage.py runserver
This is the installation guidelines mentioned on djangobb support. I'm stuck after installing the requirements.txt. How do I integrate djangobb to my existing project. Django noob here hence the need of help.
Here you can find my guide writen 2 months ago. For now I see that this guide can be few steps less, but it does not change the result :) so I don't see big reason to re-write it. If you have any question once the guide is read, pls ask.
Currently DjangoBB consist from 2 Git pieces:
3 branches for App itself (stable, default and bootstrap3)
2 branches for Project (default and dimka665/*********)
In this tutorial we are going to use bolded versions of DjangoBB.
1) stable/default/botstrap3 — means DjangoBB_Forum as App itself.
Stable branch has the latest version of code so lets use it.
Source
Zip archive
2) default — Django's skeleton project structure with all settings (urls.py, settings.py, templates, etc) needed to launch 'DjangoBB_Forum app'. This is JUST the project skeleton (similiar to ./manage.py startproject) and here DjangoBB_Forum as App is NOT included.
Source
Zip archive
Lets download both archives, extract them and for convenience rename 2 folders that we've got (both have original name 'slav0nic-djangobb-****) to DjangoBB_App for 'stable' App's branch and to DjangoBB_Project for 'default' Project's branch. (We age going to combine files\datas of both archives)
Instalation.
For today (19.09.2015) the latest version of Django is 1.8.4. This tutorial also is 100% applicable for 1.8.2 and 1.8.3. I've not tested earlier versions of Django.
Now DjangoBB_Forum requirements look like this:
Django>=1.6,<1.9 (the actual latest stable version is 1.8.4)
django-haystack>=2.1.0,<2.4 (actual version for the time of this
tutorial is 2.4)
Pillow>=2.1.0 (actual version is 2.9.0)
postmarkup (actual version is 1.2.2)
pygments (actual version is 2.0.2)
pytz>=2015.4 (this is actual version)
django-pagination-py3==1.1.1 (this actual version)
django-allauth (actual version is 0.23.0)
django-messages (actual version is 0.5.1)
django-nocaptcha-recaptcha (actual version is 0.0.18)
whoosh (actual version is 2.7.0)
The biggest problem here with integration DjangoBB_Forum to existing project is settings, because they are different from user to user. I show you my structure as example, prepared urls.py and settings.py to let you to integrate new settings to your project easily with all necessary explanations. Before to use settings.py below, you need to change DATABASES section there with your DB settings. Also much more below you will see 2nd screen with labels for folders\files which explain you what to change in settings.py in, because you have for sure another absolute paths and possibly another relative paths.
Also want to mention, that on the screeens you will see instead of 'settings/settings.py' file, 3 other files (default_settings.py, development.py, production.py). In the manual, saying 'settings.py' I mean YOUR 'settings.py' file whatever it calls, instead of files on the screen.
Initial structure of our project which is ready to accept djangobb_forum (app_shows_and_times and app_places are used just to make feeling of the existing project to which we add djangobb_forum):
/src/bugaga/urls.py
"""bugaga URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.8/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Add an import: from blog import urls as blog_urls
2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls))
"""
from django.conf.urls import *
from django.conf import settings
from django.contrib import admin
from django.conf.urls.static import static
from djangobb_forum import settings as forum_settings
from djangobb_forum.sitemap import SitemapForum, SitemapTopic
sitemaps = {
'forum': SitemapForum,
'topic': SitemapTopic,
}
urlpatterns = patterns('',
# Admin
url(r'^admin/', include(admin.site.urls)),
# Sitemap
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
#My_Apps
url(r'^places/', include('app_places.urls')),
url(r'^shows/', include('app_shows_and_times.urls')),
# DjangoBB_Forum
url(r'^forum/account/', include('allauth.urls')),
url(r'^forum/', include('djangobb_forum.urls', namespace='djangobb')),
)
# PM Extension
if (forum_settings.PM_SUPPORT):
urlpatterns += patterns('',
url(r'^forum/pm/', include('django_messages.urls')),
)
if (settings.DEBUG):
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
/src/bugaga/settings/development.py
# -*- coding: utf-8 -*-
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
#print ("base dir path", BASE_DIR)
ADMINS = (
# ('Your Name', 'your_email#domain.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'name_of_db',
'USER': 'login_to_db',
'PASSWORD': 'pass_to_db',
'HOST': 'localhost',
'PORT': '',
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'ru-RU'
LANGUAGES = (
('ca', 'Catalan'),
('cs', 'Czech'),
('de', 'German'),
('en', 'English'),
('es', 'Spanish'),
('fo', 'Faroese'),
('fr', 'France'),
('it', 'Italian'),
('lt', 'Lithuanian'),
('mn', 'Mongolian'),
('nl', 'Dutch'),
('pl', 'Polish'),
('ru', 'Russian'),
('uk_UA', 'Ukrainian'),
('vi', 'Vietnamese'),
('zh_CN', 'Chinese'),
)
SITE_ID = 1
# 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 = 'Europe/Kiev'
USE_TZ = True
# 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
# STATIC_ROOT is where the static files get placed from STATIC_URL and STATICFILES_DIRS
# when they are collected by "manage.py collectstatic". Static files are used by Apache\nginx
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
#When you’re developing using Django’s development server, you won’t have anything to do with this setting.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = "/home/antonio/projects/bugaga.com/static/"
# URL prefix for static files in your apps
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# STATICFILES_DIRS is a setting you use to declare non app-specific static files
# You can prefixes for templates, as STATICFILES_DIRS = (("downloads", "/opt/webfiles/stats"),)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
#'/var/www/static/',
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder', # is default; responsible for STATICFILES_DIRS
'django.contrib.staticfiles.finders.AppDirectoriesFinder', # is default; responsible for $app_name/static/
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = '/home/antonio/projects/bugaga.com/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 = '/media/'
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'YOUR_SECRET_KEY GENERATED BY DJANGO'
# Make this unique, and don't share it with anybody.
if not hasattr(globals(), 'SECRET_KEY'):
SECRET_FILE = os.path.join(BASE_DIR, 'secret.txt')
try:
SECRET_KEY = open(SECRET_FILE).read().strip()
except IOError:
try:
from random import choice
import string
symbols = ''.join((string.lowercase, string.digits, string.punctuation ))
SECRET_KEY = ''.join([choice(symbols) for i in range(50)])
secret = file(SECRET_FILE, 'w')
secret.write(SECRET_KEY)
secret.close()
except IOError:
raise Exception('Please create a %s file with random characters to generate your secret key!' % SECRET_FILE)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
#DjangoBB_Forum part
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.locale.LocaleMiddleware',
'pagination.middleware.PaginationMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
'djangobb_forum.middleware.LastLoginMiddleware',
'djangobb_forum.middleware.UsersOnline',
'djangobb_forum.middleware.TimezoneMiddleware',
)
ROOT_URLCONF = 'bugaga.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
# Directories where the engine should look for template source files, in search order.
# 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.
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
#DjangoBB_Forum part
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django_messages.context_processors.inbox',
#'allauth.account.context_processors.account', #not required since v0.21.0
#'allauth.socialaccount.context_processors.socialaccount', #not required since v0.21.0
'djangobb_forum.context_processors.forum_settings',
],
#DjangoBB_Forum part
#'loaders': [
# 'django.template.loaders.filesystem.Loader', #is the same as DIRS [] not empty
# 'django.template.loaders.app_directories.Loader', #is the same as APP_DIRS = True
# 'django.template.loaders.eggs.Loader',
#]
},
},
]
PREREQ_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MY_APPS = [
'app_places',
'app_shows_and_times',
]
DJANGOBB_APPS = [
'django.contrib.sites', #required by django-allauth
'django.contrib.sitemaps',
'django.contrib.admindocs',
'django.contrib.humanize',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.openid',
#'allauth.socialaccount.providers.facebook', # at first you need to configure Facebook or
# you will get Error: No Facebook app configured: please add a SocialApp using the Django admin
'allauth.socialaccount.providers.google',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.vk',
'pagination',
'haystack',
'django_messages',
'nocaptcha_recaptcha',
'djangobb_forum',
]
INSTALLED_APPS = PREREQ_APPS + MY_APPS + DJANGOBB_APPS
# 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,
},
}
}
try:
import mailer
INSTALLED_APPS += ('mailer',)
EMAIL_BACKEND = "mailer.backend.DbBackend"
except ImportError:
pass
try:
import south
INSTALLED_APPS += ('south',)
SOUTH_TESTS_MIGRATE = False
except ImportError:
pass
FORCE_SCRIPT_NAME = ''
# Haystack settings
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
'PATH': os.path.join(BASE_DIR, 'djangobb_forum/djangobb_index'),
'INCLUDE_SPELLING': True,
},
}
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'
# Account settings
ACCOUNT_ACTIVATION_DAYS = 10
LOGIN_REDIRECT_URL = '/forum/'
LOGIN_URL = '/forum/account/login/'
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
# Cache settings
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
# Allauth
ACCOUNT_LOGOUT_ON_GET = True
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_SIGNUP_FORM_CLASS = 'bugaga.forms.SignupForm'
try:
from local_settings import *
except ImportError:
pass
(0) Lets imagine that we have project_name/src folder somewhere in VirtualEnvironment (should be already installed (properly built-in feature of Python since v3.4)), which we are going to use as the project folder.
Copy all the entire content from
djangobb_project/basic_project/media/*
to
/bugaga.com/media/
Copy all the entire content from
djangobb_project/basic_project/templates/*
to
/bugaga.com/src/templates/
Copy
djangobb_project/basic_project/forms.py
to
/bugaga.com/bugaga.com/src/settings/
Copy from
djangobb_app/ the next stuff:
'djangobb_forum' folder
'requirements.txt' file
'requirements_optional.txt' file
to
/bugaga.com/bugaga.com/src/
Now you should have the next structure (new stuff marked by black arrows)
activate your virtenv (see step #0)
cd to '/bugaga.com/bugaga.com/src/' (here is my path to my project)
run 'pip install -r requirements.txt' (pip should be also installed long time ago)
run 'pip install -r requirements_optional.txt'
run 'pip install django-nocaptcha-recaptcha'
run 'pip install whoosh'
in '/bugaga.com/bugaga.com/src/' create a file 'secret.txt' and put there any random string you like, for example 'asd423llkmasdi2'
Now try to './manage.py runsever' and open http://127.0.0.1:8000/forum/. If you get error like:
settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
This means you need to properly set up your DataBase in '/bugaga.com/bugaga.com/src/settings/settings.py'.
From the box (means by default) we have the next settings for DB:
.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # 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.
}
}
As I use PostgreSQL, I can provide DB template for PostgreSQL:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'name_of_db',
'USER': 'login_to_db',
'PASSWORD': 'pass_to_db',
'HOST': 'localhost',
'PORT': '',
}
}
If you did not see the error above, then you should see the error below:
django.db.utils.ProgrammingError: relation "djangobb_forum_forum" does not exist
LINE 1: ...user"."is_active", "auth_user"."date_joined" FROM "djangobb_…
:)
run './manage.py migrate'
If you got error:
django.db.utils.ProgrammingError: relation "auth_user" does not exist
-> run './manage.py migrate auth'
If you got error:
psycopg2.ProgrammingError: relation "django_site" does not exist
LINE 1: SELECT (1) AS "a" FROM "django_site" LIMIT 1
-> run './manage.py migrate sites'
run './manage.py migrate' (it migrates the rest apps all together so you dont need to specify the name each of them).
run './manage.py makemigrations'
Again run './manage.py migrate'
Before you can open in the browser your forum, you need to have an account ('./manage.py createsuperuser') othewise you will get errors:
in browser: User matching query does not exist.
in console: django.contrib.auth.models.DoesNotExist: User matching query does not exist.
Also to avoid error:
ImportError: No module named 'allauth.account.context_processors'
-> open 'bugaga.com/bugaga.com/src/settings/settings.py' and in the TEMPLATE_CONTEXT_PROCESSORS section comment (by #) 2 lines like this:
# 'allauth.account.context_processors.account',
# 'allauth.socialaccount.context_processors.socialaccount',
Now we can open our forum but there is 1 remained issue with languages. To fix it, cd to '/src/djangobb_forum/' and run 'django-admin compilemessages'
Now you can run './manage.py runserver' and welcome to DjangoBB_Forum http://127.0.0.1:8000/forum/
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.
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.
Hello and thank you in advance.
I have django installed on Bluehost. Everything seems to be working, but the admin module isn't seeing the static files so the admin pages are not formatted.
I am a noob and I am not sure where to start troubleshooting, any help is appreciated. Please let e know what information would be helpful to supply.
<pre>
# Django settings for acme project.
DEBUG = True
TEMPLATE_DEBUG
= DEBUG
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'XXXXXXX', # Or path to database file if using sqlite3.
'USER': 'XXXXXXXX', # Not used with sqlite3.
'PASSWORD': 'XXXX', # 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.
'home/public_html/chicken/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 = '#rrbgcl4dl5sr$7)5pb5)b+4tt$9glpj)zs0+--edu!id9&vpt'
# 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 = 'acme.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'acme.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,
},
}
}
</pre>
django.fcgi (in a sub directory under public_html)
<pre>
#!/home/acmefant/bin/python
import sys, os
sys.path.insert(0,"/home/acmefant/django_src")
sys.path.insert(0,"/home/acmefant/django_projects/acme")
from flup.server.fcgi import WSGIServer
os.environ['DJANGO_SETTINGS_MODULE'] = 'acme.settings'
from django.core.handlers.wsgi import WSGIHandler
WSGIServer(WSGIHandler()).run()
</pre>
.htaccess (in the same sub directory)
<pre>
AddHandler fcgid-script .fcgi
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
RewriteRule ^(adminmedia/.*)$ - [L]
RewriteRule ^(django\.fcgi/.*)$ - [L]
RewriteRule ^(.*)$ /chicken/django.fcgi/$1 [L]
</pre>
I have been troubleshooting this for a few days and I am at the end of my rope..
Thank you,
dp
Make sure following is included in your settings.py
ADMIN_MEDIA_PREFIX = '/static/admin/'
You'll probably need to set ADMIN_MEDIA_PREFIX to a fully qualified url.
Like
ADMIN_MEDIA_PREFIX = 'http://yourdoman.com/static/admin/'
and make sure your server is serving the static files.
For anyone else who runs across this, bluehost does not allow the normal methods that you would use to direct requests for static resources on the admin page via mod_rewrite (detailed here). Specifically, Alias and Options +FollowSymLinks are disallowed.
The way we got this working was creating a static/ dir under public_html. We then copied all of the relevant Django css/img/js folder structures into that static folder, and used a simpler .htaccess file:
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_URI} !(mysite.fcgi)
RewriteRule ^(.*)$ mysite.fcgi/$1 [L]
All I had to do was create a directory called static and copy over python/lib/site-packages/django/contrib/admin/static/* to there. Done.
I moved the site to WebFaction and it works.