debug toolbar django not executing - django

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("\\", "/"),
]

Related

Static resources that get served over http don't get served over https

I wrote an application with Django that serves files built with Webpack. The application runs fine over http, but gives an error over https that I can't seem to find how to solve.
With debug set to True I get (for example)
GET https://localhost:8000/dist/bundles/css/main.f57231b6.css net::ERR_ABORTED 404 (Not Found)
with debug set to false I get
GET https://localhost:8000/dist/bundles/css/main.f57231b6.css net::ERR_ABORTED 500 (Internal Server Error)
for css and javaScript. The traceback on the server looks like this:
File "/Applications/anaconda3/lib/python3.6/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/Users/home/docs/Projects/Apprentice_Project/aws_env/lib/python3.6/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
return super().__call__(environ, start_response)
File "/Users/home/docs/Projects/Apprentice_Project/aws_env/lib/python3.6/site-packages/django/core/handlers/wsgi.py", line 146, in __call__
response = self.get_response(request)
File "/Users/home/docs/Projects/Apprentice_Project/aws_env/lib/python3.6/site-packages/django/contrib/staticfiles/handlers.py", line 62, in get_response
return super().get_response(request)
File "/Users/home/docs/Projects/Apprentice_Project/aws_env/lib/python3.6/site-packages/django/core/handlers/base.py", line 81, in get_response
response = self._middleware_chain(request)
TypeError: 'NoneType' object is not callable
[01/Aug/2018 05:48:59] "GET /dist/bundles/css/main.f57231b6.css HTTP/1.1" 500 59
Can anyone tell me why I'm getting the NoneType error with https?
settings.py:
"""
Django settings for prentice project.
Generated by 'django-admin startproject' using Django 2.0.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""
import os
import environ
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# defining which variables django-environ should look for
env = environ.Env(
SECRET_KEY=str,
DB_HOST=(str, '127.0.0.1'),
DB_NAME=str,
DB_USER=str,
DB_PASSWORD=str,
DB_PORT=int
)
#Read environment variables
environ.Env.read_env(os.path.join(BASE_DIR, '.env.prod'))
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
# Set to 'True' for dev environment
DEBUG = True
ALLOWED_HOSTS = ['localhost', 'prentice.us-east-1.elasticbeanstalk.com']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# 3rd party apps
'webpack_loader',
'knox',
'sslserver',
# Custom apps
...
]
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',
'whitenoise.middleware.WhiteNoiseMiddleware',
]
ROOT_URLCONF = 'configuration.urls'
WSGI_APPLICATION = 'configuration.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
if 'RDS_DB_NAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
else:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': env('DB_NAME'),
'USER': env('DB_USER'),
'PASSWORD': env('DB_PASSWORD'),
'HOST': env('DB_HOST'),
'PORT': env('DB_PORT'),
}
}
#Substitute custom User model
AUTH_USER_MODEL = 'auth_api.User'
# 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',
},
]
# Rest framework settings
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': ('knox.auth.TokenAuthentication',),
}
# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'America/Dawson'
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 = '/dist/'
STATIC_ROOT = 'dist'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "dist","bundles"),
]
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "dist", "bundles"), ],
'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',
],
},
},
]
WEBPACK_LOADER = {
'DEFAULT': {
'BUNDLE_DIR_NAME': 'bundles/',
'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.prod.json'),
}
}
I think :
With debug turned off Django won't handle static files for you any more - your production web server (Apache or django-whitenoise ) should take care of that
I hope it helps :)

Django error : smtplib.SMTPDataError

>>> from django.core.mail import send_mail>>> send_mail("allo", 'here is the message', 'my_email#gmail.com', ['my_email#gmail.com'], fail_silently=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/jeremie/Desktop/email_test/myvenv/lib/python3.5/site-packages/django/core/mail/__init__.py", line 62, in send_mail
return mail.send()
File "/home/jeremie/Desktop/email_test/myvenv/lib/python3.5/site-packages/django/core/mail/message.py", line 348, in send
return self.get_connection(fail_silently).send_messages([self])
File "/home/jeremie/Desktop/email_test/myvenv/lib/python3.5/site-packages/django/core/mail/backends/smtp.py", line 111, in send_messages
sent = self._send(message)
File "/home/jeremie/Desktop/email_test/myvenv/lib/python3.5/site-packages/django/core/mail/backends/smtp.py", line 127, in _send
self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
File "/usr/lib/python3.5/smtplib.py", line 883, in sendmail
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (421, b'4.3.0 collect: Cannot write ./dfv4IKaDvq007500 (bfcommit, uid=0, gid=133): No such file or directory')
I did export DJANGO_SETTINGS_MODULE=email_name.settings in bash where email_name is the name of my django app. Because as you could see I am working with interactive python.
I am trying to send an email, and I obtain this error. How could I fix this issue?
Thanks!
P.S. If the question is unclear, please let me know.
The settings.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__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '*^-s1-k$lz4noyi0yhz89&bmw1pz5g^pufkswal7#efva(_-fj#'
# 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 = [
'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 = 'email_name.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 = 'email_name.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.11/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/1.11/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/1.11/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.11/howto/static-files/
STATIC_URL = '/static/'
Notice that I am not looking for to create a django project, but rather test out the method send_mail(). That's why the code settings.py is standard.
I believe in your settings.py you are going to need to add some email configuration, like this
EMAIL_FROM = 'youremail#gmail.com'
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'something#gmail.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
Then you could create a view that calls the send_mail function. Something like this
def send_an_email(request):
from django.core.mail import send_mail
send_mail('Subject here', 'Here is the message.', 'from#example.com', [to#example.com'], fail_silently=False,)
return render(request, '/email_sent.html')
Reference
Of course you'll need a url to call this view. So in your urls.py (I assume you have this already) have something like this
url(r'^send_my_mail/', 'Project_name.views.mail.send_an_email', name='mail')
And then visit the url to see if the email got sent properly.

Can't define default cache Django

I'm trying to setup caching in Django, but it won't let me define a default cache.
I'm not overly concerned with what type of cache I use (I have tried Filesystem and Database Cache.)
But even when copy + pasting their example code the error checker tells me:
?: (caches.E001) You must define a 'default' cache in your CACHES setting.
I have also tried to put the CACHES setting at the bottom of the settings.py file to make sure anything the CACHES setting might depend on is initialized.
My code is as follows:
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
The full error message is:
Unhandled exception in thread started by <function check_errors.
<locals>.wrapper at 0x0436A300>
Traceback (most recent call last):
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\utils\autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\core\management\commands\runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "C:\Users\Kasper\Documents\kasperfred-blog\kasperfred-blog\lib\site-packages\django\core\management\base.py", line 472, in check
raise SystemCheckError(msg)
django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:
ERRORS:
?: (caches.E001) You must define a 'default' cache in your CACHES setting.
Most of the settings file (edited out secret key)
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__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'Sorry'
# 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',
'posts',
# Third party
'trumbowyg',
'crispy_forms',
'taggit',
'imagefit',
]
CRISPY_TEMPLATE_PACK = 'bootstrap3'
TAGGIT_CASE_INSENSITIVE = True
# Image fit settings
IMAGEFIT_ROOT = "public"
IMAGEFIT_PRESETS = {
'card_small': {'width': 64, 'height': 64, 'crop': True},
'my_preset1': {'width': 300, 'height': 220},
'my_preset2': {'width': 100},
}
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
]
ROOT_URLCONF = 'kasperfred_blog.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 = 'kasperfred_blog.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/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/1.9/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/1.9/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.9/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = "/media/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
#'/var/www/static/',
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")
MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media_cdn")
# Cache
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/django_cache',
}
}
This problem is being caused by imagefit, which overwrites the CACHES setting when it is loaded:
settings.CACHES = {
IMAGEFIT_CACHE_BACKEND_NAME: {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': os.path.join(tempfile.gettempdir(), 'django_imagefit')
}
}
Apparently the issue was recently fixed - so it should work if you can get the latest version.
I can't tell from the Github repository whether a new release was issue on PyPi after this change was made.

Django_facebook api integration- A server error occurred. Please contact the administrator

I am new to django and trying to integrate django_facebook api in my django website that i am currently running on localhost. I am getting an error saying A server error occurred. Please contact the administrator.I have attached the error log and other files so that it can help in figuring out the cause of error.
urls.py
from django.conf.urls import patterns, url, include
from . import views
app_name='polls'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
url(r'^(?P<pk>[0-9]+)/results/$', views.ResultsView.as_view(), name='results'),
url(r'^(?P<question_id>[0-9]+)/vote/$', views.vote, name='vote'),
url(r'^facebook/', include('django_facebook.urls')),
url(r'^accounts/', include('django_facebook.auth_urls')),
]
error-log
Traceback (most recent call last):
File "/usr/lib/python3.4/wsgiref/handlers.py", line 137, in run
self.result = application(self.environ, self.start_response)
File "/home/shivani/newproject/newenv/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 63, in __call__
return self.application(environ, start_response)
File "/home/shivani/newproject/newenv/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 158, in __call__
self.load_middleware()
File "/home/shivani/newproject/newenv/lib/python3.4/site-packages/django/core/handlers/base.py", line 53, in load_middleware
mw_instance = mw_class()
TypeError: facebook() missing 1 required positional argument: 'request'
[03/Jan/2016 15:02:41] "GET /favicon.ico HTTP/1.1" 500 59
settings.py
""" Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.9.
For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""
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__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '3qx%oiuq#zyb#f)bnnk3-j4cnt&1p=o#&8bxx5l))wwkn#c!)r'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'polls.apps.PollsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_facebook',
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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_facebook.context_processors.facebook',
'django.core.context_processors.request',
]
AUTHENTICATION_BACKENDS = (
'django_facebook.auth_backends.FacebookBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_USER_MODEL = 'django_facebook.FacebookCustomUser'
AUTH_PROFILE_MODULE = 'django_facebook.FacebookProfile'
ROOT_URLCONF = 'mysite.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',
'django_facebook.context_processors.facebook',
'django.core.context_processors.request',
],
},
},
]
WSGI_APPLICATION = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.9/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/1.9/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/1.9/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_URL = '/static/'
#facebook details
FACEBOOK_APP_ID = 'something'
FACEBOOK_APP_SECRET = 'something'
I am unable to figure out the reason of the error.

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