Template Error in Django - 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')

Related

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).

debug toolbar django not executing

I've been trying to use the debug Toolbar from django by applying the docs.
Before adding the INTERNAL_IPS=['127.0.0.1'] on settings.py, django can be executed locally and i can run it, but the toolbar doesn't appear.
Once I add the INTERNAL_IPS=['127.0.0.1'], I get the following error:
Internal Server Error: /
Traceback (most recent call last):
File "C:\Anaconda3\envs\mydjan\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
response = get_response(request)
File "C:\Anaconda3\envs\mydjan\lib\site-packages\django\utils\deprecation.py", line 97, in __call__
response = self.process_response(request, response)
File "C:\Anaconda3\envs\mydjan\lib\site-packages\debug_toolbar\middleware.py", line 133, in process_response
panel.generate_stats(request, response)
File "C:\Anaconda3\envs\mydjan\lib\site-packages\debug_toolbar\panels\staticfiles.py", line 136, in generate_stats
"staticfiles_finders": self.get_staticfiles_finders(),
File "C:\Anaconda3\envs\mydjan\lib\site-packages\debug_toolbar\panels\staticfiles.py", line 148, in get_staticfiles_finders
for path, finder_storage in finder.list([]):
File "C:\Anaconda3\envs\mydjan\lib\site-packages\django\contrib\staticfiles\finders.py", line 125, in list
for path in utils.get_files(storage, ignore_patterns):
File "C:\Anaconda3\envs\mydjan\lib\site-packages\django\contrib\staticfiles\utils.py", line 28, in get_files
directories, files = storage.listdir(location)
File "C:\Anaconda3\envs\mydjan\lib\site-packages\django\core\files\storage.py", line 313, in listdir
for entry in os.listdir(path):
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Alvaro Lloret\\Home\\alpha_trader\\static\\'
[10/Jan/2019 20:14:30] "GET / HTTP/1.1" 500 94293
Find hereby my settings.py:
import os
from django.contrib.messages import constants as messages
# 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/2.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'n2th-ublablalablablals'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
# 'django.contrib.admin', # https://stackoverflow.com/a/44651902/5176549
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'django.contrib.humanize',
'crispy_forms',
'accounts'
]
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',
'debug_toolbar.middleware.DebugToolbarMiddleware',
]
ROOT_URLCONF = 'alpha_trader.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 = 'alpha_trader.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.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/2.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/2.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/2.0/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
# Custom Django auth settings
AUTH_USER_MODEL = 'accounts.User'
LOGIN_URL = 'login'
LOGOUT_URL = 'logout'
LOGIN_REDIRECT_URL = 'home'
LOGOUT_REDIRECT_URL = 'home'
# Messages built-in framework
MESSAGE_TAGS = {
messages.DEBUG: 'alert-secondary',
messages.INFO: 'alert-info',
messages.SUCCESS: 'alert-success',
messages.WARNING: 'alert-warning',
messages.ERROR: 'alert-danger',
}
# Third party apps configuration
CRISPY_TEMPLATE_PACK = 'bootstrap4'
INTERNAL_IPS=['127.0.0.1']
Any idea why it is not working? It seems it is adding double slashes on my directory, but I don't know why.
Thank you in advance.
According to the django docs for STATICFILES_DIRS, even on windows you need to pass the path in a Unix-style format:
Note that these paths should use Unix-style forward slashes, even on
Windows (e.g. "C:/Users/user/mysite/extra_static_content").
Solution
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static').replace("\\", "/"),
]

How to solve '[Errno 111] Connection Refused' in Django app on Heroku?

I have just added a new app to my Django application, and everything was working fine locally. When I push it Heroku however, I get the following error when trying to access views from the new app, or admin pages related to it. The rest of the site is working fine.
Error (from the heroku application logs):
2017-02-15T10:14:13.305769+00:00 app[web.1]: self.connection = connection_class(self.host, self.port, **connection_params)
2017-02-15T10:14:13.305769+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/smtplib.py", line 256, in __init__
2017-02-15T10:14:13.305770+00:00 app[web.1]: (code, msg) = self.connect(host, port)
2017-02-15T10:14:13.305770+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/smtplib.py", line 316, in connect
2017-02-15T10:14:13.305771+00:00 app[web.1]: self.sock = self._get_socket(host, port, self.timeout)
2017-02-15T10:14:13.305771+00:00 app[web.1]: return socket.create_connection((host, port), timeout)
2017-02-15T10:14:13.305771+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/smtplib.py", line 291, in _get_socket
2017-02-15T10:14:13.305772+00:00 app[web.1]: File "/app/.heroku/python/lib/python2.7/socket.py", line 575, in create_connection
2017-02-15T10:14:13.305772+00:00 app[web.1]: raise err
2017-02-15T10:14:13.305773+00:00 app[web.1]: error: [Errno 111] Connection refused
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.dirname(__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 = ******
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = ['*']
ADMINS = (
(***, ***),
)
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'feed',
'cv',
'hon',
'blog',
'markdown_deux',
)
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 = 'Site.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 = 'Site.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'),
}
}
# Parse database configuration from $DATABASE_URL
import dj_database_url
DATABASES['default'] =
dj_database_url.config(default=os.environ.get('DATABASE_URL'))
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
# 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/
import os
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, '../../feed/static/'),
)
I couldn't find much documentation for this particular error, so any help would be much appreciated. What's going wrong? Let me know if there's any more information I can provide that would help.
Update: Regarding the first two comments, my 'application' is a static website apart from the django admin backend, and I'm not trying to send emails anywhere in my code. The page that generates the error logs above is just the homepage of a simple blog, listing all the posts (of which there currently are none, because I'm unable to add any).
I'm not sure what the cause was, but this issue resolved itself after I made a dummy-change to one of the files (adding a space at the end of a line), and re-pushed the application to Heroku.

django 1.8 cannot load css in development server

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.

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"