Error when upload files to Azure Blob storage through Django App - django

I need to build a file manager to upload images from a Django app to Azure blob storage. However, when I try to upload a file to Azure's blob storage, I get the following error:
Traceback (most recent call last):
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/website/files/views.py", line 27, in upload_file
new_file=upload_file_to_blob(file)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/website/files/azure_controller.py", line 57, in upload_file_to_blob
blob_client =create_blob_client(file_name = file_name) #problem
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/website/files/azure_controller.py", line 20, in create_blob_client
storage_credentials = secret_client.get_secret(name=settings.AZURE_STORAGE_KEY_NAME) #problem
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 78, in wrapper_use_tracer
return func(*args, **kwargs)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/keyvault/secrets/_client.py", line 72, in get_secret
bundle = self._client.get_secret(
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/keyvault/secrets/_generated/_operations_mixin.py", line 1574, in get_secret
return mixin_instance.get_secret(vault_base_url, secret_name, secret_version, **kwargs)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/tracing/decorator.py", line 78, in wrapper_use_tracer
return func(*args, **kwargs)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/keyvault/secrets/_generated/v7_3/operations/_key_vault_client_operations.py", line 694, in get_secret
pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 211, in run
return first_node.send(pipeline_request) # type: ignore
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 71, in send
response = self.next.send(request)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 71, in send
response = self.next.send(request)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/pipeline/_base.py", line 71, in send
response = self.next.send(request)
[Previous line repeated 2 more times]
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/pipeline/policies/_redirect.py", line 160, in send
response = self.next.send(request)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/pipeline/policies/_retry.py", line 512, in send
raise err
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/pipeline/policies/_retry.py", line 484, in send
response = self.next.send(request)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/core/pipeline/policies/_authentication.py", line 116, in send
self.on_request(request)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/keyvault/secrets/_shared/challenge_auth_policy.py", line 71, in on_request
_enforce_tls(request)
File "/Users/marilynmarquez/Desktop/webster/python/file_manager/venv/lib/python3.10/site-packages/azure/keyvault/secrets/_shared/challenge_auth_policy.py", line 41, in _enforce_tls
raise ServiceRequestError(
azure.core.exceptions.ServiceRequestError: Bearer token authentication is not permitted for non-TLS protected (non-https) URLs.
[06/Feb/2023 18:44:58] "POST /upload_file/ HTTP/1.1" 500 155467
This is my azure_controller.py:
from io import BytesIO
import uuid
from pathlib import Path
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
from azure.storage.blob import BlobClient
from django.conf import settings
from . import models
ALLOWED_EXTENSIONS = ['.png', '.jpg']
def create_blob_client(file_name):
default_credential = DefaultAzureCredential()
secret_client=SecretClient(
vault_url = settings.AZURE_VAULT_ACCOUNT,
credential = default_credential
)
storage_credentials = secret_client.get_secret(name=settings.AZURE_STORAGE_KEY_NAME)
return BlobClient(
account_url = settings.AZURE_STORAGE_ACCOUNT,
container_name = settings.AZURE_APP_BLOB_NAME,
blob_name = file_name,
credential = storage_credentials.value,
)
def check_file_ext(path):
ext = Path(path).suffix
return ext in ALLOWED_EXTENSIONS
def download_blob(file):
blob_client=create_blob_client(file)
if not blob_client.exists():
return
blob_content = blob_client.download_blob()
return blob_content
def save_file_url_to_db(file_url):
new_file = models.File.objects.create(file_url = file_url)
new_file.save()
return new_file
def upload_file_to_blob(file):
if not check_file_ext(file.name):
return
file_prefix = uuid.uuid4().hex
ext=Path(file.name).suffix
file_name = f"{file_prefix}{ext}"
file_content = file.read()
file_io = BytesIO(file_content)
blob_client =create_blob_client(file_name = file_name)
blob_client.upload_blob(data=file_io)
file_object=save_file_url_to_db(blob_client.url)
return file_object
This is my settings.py:
Django settings for website project.
from pathlib import Path
import environ
BASE_DIR = Path(__file__).resolve().parent.parent
env = environ.Env()
environ.Env.read_env()
AZURE_STORAGE_ACCOUNT=env.str('AZURE_STORAGE_ACCOUNT')
AZURE_VAULT_ACCOUNT=env.str('AZURE_VAULT_ACCOUNT')
AZURE_STORAGE_KEY_NAME=env.str('AZURE_STORAGE_KEY_NAME')
AZURE_APP_BLOB_NAME=env.str('AZURE_APP_BLOB_NAME')
SECRET_KEY = env('MY_SECRET')
DEBUG = True
ALLOWED_HOSTS = []
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'files',
'django_extensions',
]
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 = 'website.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 = 'website.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
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',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
STATIC_URL = 'static/'
# Default primary key field type
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Some of the documentation I read advises using a Security Prncipal in Azure, which implies setting up Azure AD, but every time I try to go to Azure AD in my account, I get a message saying I'm not allowed (I'm the owner of the account). I honestly have no idea where to go from here or how to begin to fix this. Can someone help?
Any help will be greatly appreciated

Related

Site matching query does not exist. Django/Heroku

My site appears to deploy correctly on heroku, I can access the main page fine but when I try to login or signup (which directs to a new page) I get the following error:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/app/.heroku/python/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/django/views/generic/base.py", line 69, in view
return self.dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/django/views/decorators/debug.py", line 90, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/allauth/account/views.py", line 146, in dispatch
return super(LoginView, self).dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/allauth/account/views.py", line 74, in dispatch
response = super(RedirectAuthenticatedUserMixin, self).dispatch(
File "/app/.heroku/python/lib/python3.9/site-packages/django/views/generic/base.py", line 101, in dispatch
return handler(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/allauth/account/views.py", line 90, in get
response = super(AjaxCapableProcessFormViewMixin, self).get(
File "/app/.heroku/python/lib/python3.9/site-packages/django/views/generic/edit.py", line 135, in get
return self.render_to_response(self.get_context_data())
File "/app/.heroku/python/lib/python3.9/site-packages/allauth/account/views.py", line 177, in get_context_data
site = get_current_site(self.request)
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/sites/shortcuts.py", line 13, in get_current_site
return Site.objects.get_current(request)
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/sites/models.py", line 58, in get_current
return self._get_site_by_id(site_id)
File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/sites/models.py", line 30, in _get_site_by_id
site = self.get(pk=site_id)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/app/.heroku/python/lib/python3.9/site-packages/django/db/models/query.py", line 439, in get
raise self.model.DoesNotExist(
Exception Type: DoesNotExist at /accounts/login/
Exception Value: Site matching query does not exist.
I am using all-auth for authentication purposes - but I am not sure why this error is being thrown.
Here is my settings.py
rom pathlib import Path
import os
from django.contrib.auth import login
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
[...]
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ["*"]
LOGIN_URL = '/'
LOGIN_REDIRECT_URL = '/'
LOGOUT_REDIRECT_URL = '/'
# Application definition
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',
# `allauth` needs this from django
'django.template.context_processors.request',
],
},
},
]
# added this for all-auth
[...]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
#'shops',
'testingland',
'rest_framework',
'bootstrap_modal_forms',
# all auth
# The following apps are required:
# 'django.contrib.auth',
# 'django.contrib.messages',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'widget_tweaks',
]
#django-allauth registraion settings
[...]
# 1 day
ACCOUNT_LOGIN_ATTEMPTS_TIMEOUT = 86400
SITE_ID = 1
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 = 'anybody1.urls'
WSGI_APPLICATION = 'anybody1.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
# 'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'vygr',
'USER': 'x',
'PASSWORD': 'x',
'HOST': 'localhost',
'PORT': '5432'
}
}
[...]
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
[...]
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
import django_heroku
django_heroku.settings(locals())

createsuperuser fails on postgresql only

I am able to get my code and database to work just fine locally using sqlite3. But when I try and migrate to a postgresql platform, I get errors when I try to create the superuser, but not migrate or makemigration.
(trader) bubba#tuna:~/www/src/trader $ ./manage.py makemigrations
No changes detected
(trader) bubba#tuna:~/www/src/trader $ ./manage.py migrate
Operations to perform:
Apply all migrations: accounts, admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
(trader) bubba#tuna:~/www/src/trader $ ./manage.py createsuperuser
Username (leave blank to use 'bubba'):
Email address: bubba#trader.com
Password:
Password (again):
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 "/home/bubba/Env/trader/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 79, in execute
return super().execute(*args, **options)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
output = self.handle(*args, **options)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 189, in handle
self.UserModel._default_manager.db_manager(database).create_superuser(**user_data)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/contrib/auth/models.py", line 158, in create_superuser
return self._create_user(username, email, password, **extra_fields)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/contrib/auth/models.py", line 141, in _create_user
user.save(using=self._db)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/contrib/auth/base_user.py", line 66, in save
super().save(*args, **kwargs)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/db/models/base.py", line 746, in save
force_update=force_update, update_fields=update_fields)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/db/models/base.py", line 795, in save_base
update_fields=update_fields, raw=raw, using=using,
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in send
for receiver in self._live_receivers(sender)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in <listcomp>
for receiver in self._live_receivers(sender)
File "/home/bubba/www/src/trader/accounts/signals.py", line 10, in customer_profile
group = Group.objects.get(name='customer')
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/bubba/Env/trader/lib/python3.7/site-packages/django/db/models/query.py", line 417, in get
self.model._meta.object_name
django.contrib.auth.models.DoesNotExist: Group matching query does not exist.
These are my settings
$ cat trader/settings.py
"""
Django settings for trader project.
Generated by 'django-admin startproject' using Django 3.0.6.
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
# 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 = 'boo'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1', '192.168.42.14']
ALLOWED_CIDR_NETS = ['192.168.42.0/24']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'accounts.apps.AccountsConfig',
'django_filters',
]
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 = 'trader.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 = 'trader.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'expungee',
'USER':'boo',
'PASSWORD':'boo',
'HOST':'192.168.42.13',
'PORT':'5432',
}
}
#DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, '/home/bubba/www/src/trader/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_URL = '/static/'
MEDIA_URL = '/images/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, '/static')
]
MEDIA_ROOT = os.path.join(BASE_DIR, 'static/images')
I did try
django.db.backends.postgresql
but could not even connect.
exchangedb=# \du
List of roles
Role name | Attributes | Member of
---------------+------------------------------------------------------------+-----------
administrator | Superuser, Create role, Create DB | {}
expungee | Superuser, Create role, Create DB | {}
expungeedb | | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
How do I migrate to postgres?
UPDATED:
$ cat accounts/signals.py
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
from .models import Customer
def customer_profile(sender, instance, created, **kwargs):
if created:
group = Group.objects.get(name='customer')
instance.groups.add(group)
Customer.objects.create(
user=instance,
name=instance.username,
)
print('Profile created!')
post_save.connect(customer_profile, sender=User)
replace this line with a get or create call
group, created = Group.objects.get_or_create(name='customer')
python3 manage.py migrate
python3 manage.py createsuperuser

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

Django1.8 and Mongoclient settings.DATABASES is improperly configured.

i am making an application using django 1.8 and mongoengine
But when i am trying to configure Django setting.py file to use a Dummy Database , I receive the following error
(orahienv) somya#somya-Inspiron-15-3555:/var/www/html/admin_python$ python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
July 06, 2017 - 16:57:25
Django version 1.8, using settings 'admin_python.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Performing system checks...
System check identified no issues (0 silenced).
July 06, 2017 - 17:00:15
Django version 1.8, using settings 'admin_python.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
<WSGIRequest: GET '/auth/login/?next=/'>
Internal Server Error: /auth/login/
Traceback (most recent call last):
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 164, in get_response
response = response.render()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/response.py", line 158, in render
self.content = self.rendered_content
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/response.py", line 135, in rendered_content
content = template.render(context, self._request)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/backends/django.py", line 74, in render
return self.template.render(context)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/base.py", line 208, in render
with context.bind_template(self):
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/template/context.py", line 235, in bind_template
updates.update(processor(self.request))
File "/var/www/html/admin_python/admin_app/context_processors.py", line 30, in init_menu
if request.user.is_authenticated():
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/functional.py", line 226, in inner
self._setup()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/utils/functional.py", line 359, in _setup
self._wrapped = self._setupfunc()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 22, in <lambda>
request.user = SimpleLazyObject(lambda: get_user(request))
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/contrib/auth/middleware.py", line 10, in get_user
request._cached_user = auth.get_user(request)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 174, in get_user
user = backend.get_user(user_id)
File "/var/www/html/admin_python/admin_app/backend.py", line 29, in get_user
return TblAdmin.objects.get(pk=user_id)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/query.py", line 328, in get
num = len(clone)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/query.py", line 144, in __len__
self._fetch_all()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
sql, params = self.as_sql()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 367, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 48, in pre_sql_setup
self.setup_query()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 39, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 216, in get_select
ret.append((col, self.compile(col, select_format=True), alias))
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 346, in compile
sql, params = node.as_sql(self, self.connection)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/expressions.py", line 611, in as_sql
return "%s.%s" % (qn(self.alias), qn(self.target.column)), []
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 337, in quote_name_unless_alias
r = self.connection.ops.quote_name(name)
File "/var/www/html/admin_python/orahienv/local/lib/python2.7/site-packages/django/db/backends/dummy/base.py", line 21, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
ImproperlyConfigured: settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.
[06/Jul/2017 17:00:21]"GET /auth/login/?next=/ HTTP/1.1" 500 206077
I know people asked similar question before. But it's all about the engine value. does any one know how do I solve this error with the NAME value?
setting.py -
import os
import admin_app
from django.utils import timezone
import mongoengine
"""from mongoengine import connect
connect('pom')"""
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 = 'uj8$6(ol=!w)b3-luqzb=#6(j19gkbrnp2asq6=xt%5*s2ylz('
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
SPATIALITE_LIBRARY_PATH = 'mod_spatialite'
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'admin_app',
'celery', #http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-the-django-orm-cache-as-a-result-backend
)
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',
'djangoflash.middleware.FlashMiddleware',
#'django.middleware.cache.CacheMiddleware', #http://stackoverflow.com/a/658583/2546013
)
ROOT_URLCONF = 'admin_python.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates'), os.path.join(BASE_DIR, 'media')],
'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',
'admin_app.context_processors.init_menu',
'admin_app.context_processors.server_urls',
'djangoflash.context_processors.flash',
],
},
},
]
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
MEDIA_URL = '/media/'
HOST_URL='http://127.0.0.1:8001/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media/")
WSGI_APPLICATION = 'admin_python.wsgi.application'
STATIC_URL = '/static/'
SERVER_URL = 'http://localhost:8001/'
WEBAPP_URL = 'http://localhost/webapp_angular/'
USERAPI_URL = 'http://localhost:8000/'
HOST_URL_NEW='http://localhost:8001/media/'
# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases
"""
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'admin_db',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
}
}"""
"""DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
}
}
"""
"""
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy',
'NAME': 'pom',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'localhost',
}
}
from mongoengine import connect
connect('pom', username='root', password='root')"""
DATABASES = {
'default': {
'ENGINE': '',
},
}
_MONGODB_USER = 'root'
_MONGODB_PASSWD = 'root'
_MONGODB_HOST = 'localhost'
_MONGODB_NAME = 'pom'
_MONGODB_DATABASE_HOST = \
'mongodb://%s:%s#%s/%s' \
% (_MONGODB_USER, _MONGODB_PASSWD, _MONGODB_HOST, _MONGODB_NAME)
mongoengine.connect(_MONGODB_NAME, host=_MONGODB_DATABASE_HOST)
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Kolkata'
USE_I18N = True
USE_L10N = True
USE_TZ = False
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
REST_FRAMEWORK = {
# other settings...
'DEFAULT_AUTHENTICATION_CLASSES': [],
'DEFAULT_PERMISSION_CLASSES': [],
}
LOGIN_URL = '/auth/login/'
LOGIN_REDIRECT_URL = '/'
AUTHENTICATION_BACKENDS = (
'admin_app.backend.AuthBackend',
'django.contrib.auth.backends.ModelBackend',
)
AUTH_USER_MODEL = 'admin_app.TblAdmin'
EMAIL_HOST = 'email-smtp.us-east-1.amazonaws.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'AKIAJB6VACOVZANVTC5A'
EMAIL_HOST_PASSWORD = 'Atu9qbV+X5aiwIlQzVAOVjU/AxkxMDV3X0l0FLWweSn9'
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'support#doctorinsta.com'
#LOGGING SETTING
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format' : "[%(asctime)s] %(levelname)s [%(filename)s:%(funcName)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
'simple': {
'format': '%(levelname)s %(message)s'
},
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'applogfile': {
'level':'DEBUG',
'class':'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'drinsta.log'),
'formatter': 'verbose'
},
},
'loggers': {
'django.request': {
'level': 'ERROR',
'propagate': True,
'handlers': ['applogfile',],
},
'drinsta': {
'handlers': ['applogfile',],
'level': 'DEBUG',
},
}
}
#https://docs.djangoproject.com/en/1.8/topics/http/sessions/#configuring-the-session-engine
#https://github.com/dlrust/python-memcached-stats
#We can use the following command to see the keys:
# python -m memcached_stats 127.0.0.1 11211
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'TIMEOUT' : 300 #Default
}
}
CACHE_BACKEND = 'memcached://127.0.0.1:11211/'
SESSION_ENGINE= 'django.contrib.sessions.backends.cache'
'''
RabbitMQ configurations begins
'''
#OLD FORMAT:
# BROKER_HOST = "127.0.0.1"
# BROKER_PORT = 5672 # default RabbitMQ listening port
# BROKER_USER = "admin"
# BROKER_PASSWORD = "admin"
# BROKER_VHOST = "admin" #Virtual hosts provide a way to segregate applications using the same RabbitMQ instance. Different users can have different access privileges to different vhost and queues and exchanges can be created so they only exists in one vhost.
#NEW FORMAT:
BROKER_URL = 'amqp://admin:admin#localhost:5672/admin'
'''
RabbitMQ configurations ends
'''
'''
Celery configurations begins
'''
#CELERY_BACKEND = "amqp" # telling Celery to report the results back to RabbitMQ
#'amqp' means Advanced Message Queuing Protocol
# CELERY_RESULT_DBURI = ""
CELERY_TIMEZONE = "Asia/Kolkata"
#CELERY_RESULT_BACKEND='djcelery.backends.cache:CacheBackend'
CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend'
CELERY_IMPORTS = ("tasks", )
CELERY_RESULT_PERSISTENT = True #If set to True, result messages will be persistent. This means the messages will not be lost after a broker restart. The default is for the results to be transient.
CELERY_TASK_RESULT_EXPIRES = None #Never delete the SUCCESSFUL tasks from the database. http://docs.celeryproject.org/en/latest/configuration.html#celery-task-result-expires
# CELERY_RESULT_BACKEND = 'cache+memcached://127.0.0.1:11211/'
# CELERY_CACHE_BACKEND = 'memory'
#http://www.hiddentao.com/archives/2012/01/27/processing-long-running-django-tasks-using-celery-rabbitmq-supervisord-monit/
'''
Celery configurations ends
'''
If you do not want to configure a database because you are using mongoengine instead, then remove DATABASES from your settings entirely, or change it to an empty dictionary.
DATABASES = {}
If you do include any items in your DATABASES dictionary, then they must include the ENGINE, otherwise you'll get the ImproperlyConfigured error.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
...
},
}
connect(
db='test',
username='user',
password='12345',
host='mongodb://admin:qwerty#localhost/production'
)
and change the DATABASES to DATABASES = {} section in the settings.py

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.