django 1.8 cannot load css in development server - django

I have problem to load css for admin site. I just setup django 1.8 and run development server but apparently it cannot load css with 500 error code. I cannot figure out what is the problem.
This is my setting.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = secret_key
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
)
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',
)
ROOT_URLCONF = 'rnd.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'rnd.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'rnd.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
this is the error that i get:
Traceback (most recent call last):
File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 64, in __call__
return super(StaticFilesHandler, self).__call__(environ, start_response)
File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 189, i
n __call__
response = self.get_response(request)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 54, in get_response
return self.serve(request)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 47, in serve
return serve(request, self.file_path(request.path), insecure=True)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\views.py", line
40, in serve
return static.serve(request, path, document_root=document_root, **kwargs)
File "C:\Python27\lib\site-packages\django\views\static.py", line 66, in serve
content_type, encoding = mimetypes.guess_type(fullpath)
File "C:\Python27\lib\mimetypes.py", line 290, in guess_type
init()
File "C:\Python27\lib\mimetypes.py", line 351, in init
db.read_windows_registry()
File "C:\Python27\lib\mimetypes.py", line 254, in read_windows_registry
with _winreg.OpenKey(hkcr, subkeyname) as subkey:
TypeError: must be string without null bytes or None, not str
[08/Jul/2015 11:04:29]"GET /static/admin/css/base.css HTTP/1.1" 500 59
This is url.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
]
The solution:
The root cause for this is because of the corrupted keys in the Windows Registry. I have reinstalled the python 2.7 library and it solved the problem.

The root cause for this is because of the corrupted keys(have empty string/null value) in the Windows Registry. I have reinstalled the python 2.7 library and it solved the problem.

Related

Issue with deploying Django on Heroku

Hi Guys I tried deploying my first django on heroku and i am frequently facing issues with the deployment.
I think this is something to do with my settings.py file.
I am clearly unaware with this issue python manage.py collectstatic--noinput , but i have written everything .
Thanks in Advance for help and ideas.
$ python manage.py collectstatic--noinput
Traceback(most recent call last): File "manage.py",
line 21,
in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
collected = self.collect()
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 104, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/finders.py", line 130, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python3.6/site-packages/django/contrib/staticfiles/utils.py", line 23, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 316, in listdir
for entry in os.scandir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/build_6613795b_/static'
! Error while running '$ python manage.py collectstatic --noinput'.
See traceback above for details.
You may need to update application code to resolve this error.
Or, you can disable collectstatic for this application:
$ heroku config:set DISABLE_COLLECTSTATIC=1
https://devcenter.heroku.com/articles/django-assets
! Push rejected, failed to compile Python app.
! Push failed
This is my settings.py
"""
Django settings for plausibility_annotation_framework project.
Generated by 'django-admin startproject' using Django 3.0.7.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
from dotenv import load_dotenv
load_dotenv()
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ['SECRET_KEY']
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ['DEBUG']
ALLOWED_HOSTS = ['shrouded-plateau-87096.herokuapp.com/', '127.0.0.1']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'annotating.apps.AnnotatingConfig',
'users.apps.UsersConfig',
'crispy_forms',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'plausibility_annotation_framework.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'plausibility_annotation_framework.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGIN_REDIRECT_URL = 'annotating-home'
LOGIN_URL = 'login'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')
YOu need to keep only one of the following lines in settings.py file.
#use this
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
or this
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
not both in settings.py file
Also, You can use command like:
python manage.py collectstatic

Django - 500 internal server error after a collectstatic

trying a switch in production mode (debug=False in setting.py), I launched the python manage.py collectstatic command. from that moment when I try to connect to the site it gives me an internal error 500 even if I start the command via python manage.py runserver 0.0.0.0:8000
this is my setting.py:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATE_DIR = os.path.join(BASE_DIR,'Game/template/game')
MEDIA_DIR = os.path.join(BASE_DIR,'game/media')
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '**************************************'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['<server-ip>','<server-domain>',]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'Accounts',
'Game',
'marketing',
'Blog',
'contactus',
'django_filters',
'widget_tweaks',
'debug_toolbar',
'tempus_dominus',
'bootstrap3_datetime',
'django_summernote',
'session_security',
]
SUMMERNOTE_THEME = 'bs4'
#SESSION SECURITY SETTINGS
SESSION_SECURITY_WARN_AFTER = 540
SESSION_SECURITY_EXPIRE_AFTER = 1800
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'session_security.middleware.SessionSecurityMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
ROOT_URLCONF = 'CicloPost.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'CicloPost.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE = 'it-IT'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
#MEDIA
MEDIA_ROOT =os.path.join(BASE_DIR,'game/media')
MEDIA_URL = '/media/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL= '/'
INTERNAL_IPS = ('127.0.0.1',)
i also have this error when i do collectstatic:
Post-processing 'js/plugin/revolution/css/settings.css' failed!
Traceback (most recent call last): File "manage.py", line 15, in
execute_from_command_line(sys.argv) File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/core/management/init.py",
line 381, in execute_from_command_line
utility.execute() File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/core/management/init.py",
line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv) File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/core/management/base.py",
line 316, in run_from_argv
self.execute(*args, **cmd_options) File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/core/management/base.py",
line 353, in execute
output = self.handle(*args, **options) File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 188, in handle
collected = self.collect() File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py",
line 134, in collect
raise processed File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py",
line 293, in _post_process
content = pattern.sub(converter, content) File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py",
line 194, in converter
force=True, hashed_files=hashed_files, File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py",
line 131, in _url
hashed_name = hashed_name_func(*args) File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py",
line 342, in _stored_name
cache_name = self.clean_name(self.hashed_name(name)) File "/opt/ciclo_proj/CicloPost/ciclo_env/lib/python3.6/site-packages/django/contrib/staticfiles/storage.py",
line 92, in hashed_name
raise ValueError("The file '%s' could not be found with %r." % (filename, self)) ValueError: The file
'js/plugin/revolution/css/openhand.cur' could not be found with
.
When you set DEBUG = False you'll need to have a webserver that listens to port 80 on the url specified in settings.STATIC_URL, and serves the files from the directory specified in settings.STATIC_ROOT.
I would advise against having settings.STATIC_ROOT relative to BASE_DIR (it can get confusing, and normally you'll want static files from multiple projects served by the same static web server).

Template Error in Django

In my blog folder as shown here in screen shot has the accounts folder
I then proceed to next page from home page to my signin page in accounts folder
I get the Following Error
Can someone please Help me
Here is the settings.py file
"""
Django settings for luckdrum project.
Generated by 'django-admin startproject' using Django 1.8.4.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'q^6oh!prd$jt*#sz##&n(i5$etxv-13-pr+%x9_0y$#7$tnfq('
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'blog',
)
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',
)
ROOT_URLCONF = 'luckdrum.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'luckdrum.wsgi.application'
TEMPLATE_DIRS=('/home/usman/Django Project/django-black/luckdrum/blog/templates/',
'/home/usman/Django Project/django-black/luckdrum/blog/accounts/',
)
LOGIN_REDIRECT_URL = '/'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
#STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static'), ]
TEMPLATE_DEBUG =True
ERROR CONSOLE OUTPUT:
Internal Server Error: /accounts/signin.html/
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 149, in get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 147, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/usman/Django Project/django-black/luckdrum/blog/views.py", line 27, in login
return render_to_response('accounts/signin.html')
File "/usr/local/lib/python2.7/dist-packages/django/shortcuts.py", line 39, in render_to_response
content = loader.render_to_string(template_name, context, using=using)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 96, in render_to_string
template = get_template(template_name, using=using)
File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 43, in get_template
raise TemplateDoesNotExist(template_name, chain=chain)
TemplateDoesNotExist: accounts/signin.html
[13/Dec/2015 07:06:07] "GET /accounts/signin.html/ HTTP/1.1" 500 75747
Move the template files from the accounts folder to the template folder and the static files to the appropriate static folder. Django only looks for templates files in the folder named templates.
Also change the original render_to_response to render_to_response('signin.html')

DB error: django.core.exceptions.ImproperlyConfigured

Getting this error when trying to create a fixture and run next command in terminal:
django-admin.py dumpdata data.json
Full traceback:
(project)litwisha#litwisha:~/PycharmProjects/test_project$ django-admin.py dumpdata data.json
Traceback (most recent call last):
File "/home/litwisha/.virtualenvs/project/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/base.py", line 402, in run_from_argv
connections.close_all()
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/utils.py", line 258, in close_all
for alias in self:
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/utils.py", line 252, in __iter__
return iter(self.databases)
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/utils/functional.py", line 60, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/utils.py", line 151, in databases
self._databases = settings.DATABASES
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/litwisha/.virtualenvs/project/local/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Tried this solution, but doesn't work:
When writing in shell:
from django.conf import settings
settings.configure()
get error:
RuntimeError: Settings already configured.
Maybe it because I use virtualenv? But I tried it without virtualenv, but it doesn't work. I use IDE PyCharm
settings.py:
"""
Django settings for test_project project.
Generated by 'django-admin startproject' using Django 1.8.3.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'r1n#)rahbrh6t1hb-mn_83c^7ai#ij&7d8m8mo7tdm&5q#o5t&'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app',
)
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',
)
ROOT_URLCONF = 'test_project.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'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',
],
},
},
]
WSGI_APPLICATION = 'test_project.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'test1',
'USER': 'postgres',
'PASSWORD': '1111',
'HOST': '127.0.0.1',
'PORT': '5432'
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'

Django 1.8.1 : A server error occurred. Please contact the administrator

I was working with django-1.8.1 and everything was good but when I tried again to run my server with command bellow, I get some errors :
command : python manage.py runserver
errors appeared in command-line :
> Traceback (most recent call last):
File "C:\Python34\lib\wsgiref\handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "C:\Python34\lib\site-packages\django\contrib\staticfiles\handlers.py", l
ine 63, in __call__
return self.application(environ, start_response)
File "C:\Python34\lib\site-packages\django\core\handlers\wsgi.py", line 170, i
n __call__
self.load_middleware()
File "C:\Python34\lib\site-packages\django\core\handlers\base.py", line 50, in
load_middleware
mw_class = import_string(middleware_path)
File "C:\Python34\lib\site-packages\django\utils\module_loading.py", line 24,
in import_string
six.reraise(ImportError, ImportError(msg), sys.exc_info()[2])
File "C:\Python34\lib\site-packages\django\utils\six.py", line 658, in reraise
>
> raise value.with_traceback(tb) File "C:\Python34\lib\site-packages\django\utils\module_loading.py", line
> 21, in import_string
> module_path, class_name = dotted_path.rsplit('.', 1) ImportError: polls doesn't look like a module path [24/Apr/2015 21:50:25]"GET /
> HTTP/1.1" 500 59
error appeared in browser :
A server error occurred. Please contact the administrator.
Also, I searched the web for this issue and I found something but they were not working for me.
This is my settings.py : `
"""
Django settings for havij project.
Generated by 'django-admin startproject' using Django 1.8.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '9va4(dd_pf#!(2-efc-ipiz#7fgb8y!d(=5gdmie0cces*9lih'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls' ,
)
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',
'polls',
)
ROOT_URLCONF = 'havij.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'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',
],
},
},
]
WSGI_APPLICATION = 'havij.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
STATIC_URL = '/static/'
`
And here is the urls.py :
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
# Examples:
# url(r'^$', 'havij.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
Thanks for your answering.
You've put your app name, polls, in MIDDLEWARE_CLASSES. It should only go in INSTALLED_APPs.
In other Django version (1.7) can be for 'django.middleware.security.SecurityMiddleware', in MIDDLEWARE_CLASSES.
try :
python manage.py migrate
it will create all tables for "admin"