How to integrate djangobb in an existing project? - python

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/

Related

Gunicorn cannot find system Renviron error

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

Elementary, unresolved import from my_app.views in Django (PyDev)

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.

Django 1.4 in windows 7 "No FlatPage matches the given query"

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.

django unable to open database file

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

Not able to use Django mongodb engine with Django?

I have django installed on my server with pymongo and mongoengine.My django project settings.py file :
# Django settings
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'RTSdatabase', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': 'localhost', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '27017', # Set to empty string for default. Not used with sqlite3.
'SUPPORTS_TRANSACTIONS': False,
}
}
# 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 = 't!0pa3z_(gzlb(sai&f$zs4cz9_2u=u(6&g99swo%psrastav6'
# 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 = 'RTS.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',
'RTS.RESTAPI',
)
# 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,
},
}
}
whenever i try to access the project it gives me error:
Exception Value: 'django_mongodb_engine' isn't an available database
backend. Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3' Error was: No module named django_mongodb_engine.base
I dont know what am I doing wrong here in settings file.I am following http://www.chrisumbel.com/article/django_python_mongodb_engine_mongo for help.
The code in that linked article has django_mongodb_engine.mongodb for the ENGINE setting.
You'll also need django-nonrel for this to work.
make sure your depended packages is installed correctly.
you can follow installation to fix your problem.
you can remove the default django installation by
sudo pip uninstall django
and reinstalled from Django fork(https://github.com/django-nonrel/django) with support for NoSQL databases by
sudo pip install git+https://github.com/django-nonrel/django
and remove/comment MIDDLEWARE_CLASSES from setting.py
# 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
# 'django.middleware.security.SecurityMiddleware',

Categories