I can't figure out why Django is not loading the admin page. It seems like it isn't even reading the urls.py file that I am editing - because even if I comment out the 'urlpatterns' statement, it still loads the local hello page fine once I run the server.
This is the error message:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^hello/$
^time/$
^time/plus/(\d{1,2})/$
The current URL, admin, didn't match any of these.
This is my urlpatterns code:
from django.conf.urls import patterns, include, url
from mysite.views import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
('^hello/$', hello, ),
('^time/$', current_datetime, ),
(r'^time/plus/(\d{1,2})/$', hours_ahead, ),
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls))
)
And this is a snippet os my settings.py file:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.contrib.messages.middleware.MessageMiddleware'
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)
ROOT_URLCONF = 'mysite.urls'
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'mysite.wsgi.application'
TEMPLATE_DIRS = (
'/Users/pavelfage/Desktop/Coding/mysite/Templates',
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
# 'django.contrib.messages',
# 'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'mysite.books'
)
Any help much appreciated!
I faced same problem. Uncommenting from django.contrib import admin in urls.py solved the problem.
I had the same problem. You may try this:
In your urls.py replace the call include(admin.site.urls) by this: admin.site.urls
In your setting.py if don't have any TEMPLATE_CONTEXT_PROCESSORS property (that was my situation) add this:
TEMPLATE_CONTEXT_PROCESSORS = ("django.contrib.auth.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", "django.core.context_processors.static", "django.core.context_processors.tz", "django.contrib.messages.context_processors.messages")
It seams to be roughly the default property in a normal django 1.4 configuration. Here are the docs talking about it: djangoproject-doc1 djangoproject-doc2
You may also have to uncomment the strings:
# 'django.contrib.messages',
# 'django.contrib.staticfiles',
in your INSTALLED_APPS property of the settings.py but i'm not sure about it.
Sorry about not explaining much better the reasons of those changes but I'm a django-beginner to. I just found your question corresponding to my problem and then a possible awnser.
I hope it may help you.
EDIT: as seen in a comment you may try to remove the url(...) instruction on the line concerning the url of the admin site
ben
Related
I'm using django-cookiecutter to bootstrap my project which will include api paths. Following the steps in Two Scoops of Django 1.11 to configure my urls to follow a similar pattern to this:
api/foo_app/ # GET, POST
api/foo_app/:uuid/ # GET, PUT, DELETE
api/bar_app/ # GET, POST
api/bar_app/:uuid/ # GET, PUT, DELETE
When I try to setup my project like this I'm getting the following error:
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module 'my_project.core.api_urls' from /Users/username/Development/my_project/my_project/core/api_urls.py'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
My current setup:
my_project.config.settings.base.py
ROOT_URLCONF = 'config.urls'
DJANGO_APPS = [
# Default Django apps:
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Useful template tags:
# 'django.contrib.humanize',
# Admin
'django.contrib.admin',
]
THIRD_PARTY_APPS = [
'crispy_forms', # Form layouts
'allauth', # registration
'allauth.account', # registration
'allauth.socialaccount', # registration
'rest_framework',
]
# Apps specific for this project go here.
LOCAL_APPS = [
# custom users app
'my_project.users.apps.UsersConfig',
'my_project.core.apps.CoreConfig',
]
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
my_project.config.urls.py
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views
urlpatterns = [
url(r'^users/', include('my_project.users.urls', namespace='users')),
url(r'^api/', include('my_project.core.api_urls', namespace='api')),
]
my_project.core.api_urls.urls
from django.conf.urls import url
from django.views.defaults import page_not_found
urlpattenrs = [
url(
regex=r'^users/$',
view=page_not_found,
),
]
The core app does not contain any models right now. It's just where I'm organizing all the URLs
"urlpattenrs" should be "urlpatterns" (in my_project.core.api_urls.urls) ;)
I'm using Django (1.7.3) with zinnia blog (0.15.1) and I'm having an issue for rendering the 'image for illustration' that you can add for a blog entry.
I have the following urls.py files:
My top-dir url conf
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^ecv/', include('extended_cv.urls',namespace="ecv")),
url(r'^weblog/', include('zinnia.urls', namespace='zinnia')),
url(r'^comments/', include('django_comments.urls')),
)
The settins.py file:
# -*- coding: utf-8 -*-
** Snip**
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = True
# For using django.contrib.sites
SITE_ID = 2
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pro',
'extended_cv',
'zinnia', # Added for zinnia blog usage
'django.contrib.sites',# Added for zinnia blog usage
'django_comments',# Added for zinnia blog usage
'mptt',# Added for zinnia blog usage
'tagging',# Added for zinnia blog usage
)
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',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'zinnia.context_processors.version',
)
** Snip**
USE_I18N = True
USE_L10N = True
USE_TZ = True
STATIC_URL = '/static/'
When I create an entry for zinnia using admin UI, and when I add an image, no error appear, and the new entry is saved to database with no warning. The image then appear in the server tree file at the adress TopDir/upload/zinnia/date/of/publication/index_IKd2N0d.jpeg
But, when I read the new entry from the weblog app, I correctly see the new entry, but not the image. Moreover, the server output the following error:
GET /weblog/2015/01/18/1st-entry/uploads/zinnia/2015/01/18/index_IKd2N0d.jpeg HTTP/1.1" 404 8922
I guess the issue is kind of complicated to debug, then if you need more information, I'll be happy to give you more.
Thank you.
As explain by Daniel Roseman in the comments, the answer consists into defining the variables MEDIA_URL and MEDIA_ROOT, and to rewrite the top urls.py file as explained in https://docs.djangoproject.com/en/1.7/howto/static-files/#serving-files-uploaded-by-a-user-during-development:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^ecv/', include('extended_cv.urls',namespace="ecv")),
url(r'^weblog/', include('zinnia.urls', namespace='zinnia')),
url(r'^comments/', include('django_comments.urls')),
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
And the work is done.
Ubuntu 14.04
Python 3.4.0
Django 1.7
I just followed the 4 step directions to set up flatpages, but when I ran python3 manage.py migrate, none of the DB tables for the flatpages were created. All the other tables were created, just not the ones needed to flatpages. I'm pretty puzzled by this, 'cause this isn't complicated. I added the right stuff into my settings.py --
SITE_ID = 1 # added for flatpages
# Application definition
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites', # added
'django.contrib.flatpages.urls', # added for flatpages
)
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.contrib.flatpages.middleware.FlatpageFallbackMiddleware', #added
)
...and into my urls.py (though I don't think this could affect DB table creation) --
from django.conf.urls import patterns, include, url
from django.views.generic import TemplateView
from django.contrib import admin
urlpatterns = patterns('',
# Examples:
url(r'^$', 'pets.views.home', name='home'),
url(r'^pages/', include('django.contrib.flatpages.urls')),
url(r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt',
content_type='text/plain')),
url(r'^admin/', include(admin.site.urls)),
)
...am I having a brain fart or something? I don't see why this won't work, but it's just not creating the DB tables needed for flatpages. This isn't my 1st time creating something with Django, but it is my 1st time trying out flatpages.
Yes, probably a brain fart: you've added the urls module to INSTALLED_APPS, rather than the app itself.
'django.contrib.flatpages', # added for flatpages
Could someone explain me please what I'm doing wrong? I'm trying to enable admin panel in Django 1.2. But the link http://mysite.com/admin raises 404 error, and the link http://mysite.com raises an error like this:
TypeError at /
list objects are unhashable
Request Method: GET
Request URL: http://mysite/index.wsgi/
Django Version: 1.2.4
Exception Type: TypeError
Exception Value:
list objects are unhashable
Exception Location: /usr/local/lib/python2.5/re.py in _compile, line 230
Python Executable: /usr/local/bin/python
Python Version: 2.5.5
Python Path: ['/usr/local.20100210/lib/python2.5/site-packages', '/usr/local/lib/python2.5/site-packages/setuptools-0.6c11-py2.5.egg', '/usr/local/lib/python2.5/site-packages/Genshi-0.6-py2.5.egg', '/usr/local/lib/python2.5/site-packages/Babel-0.9.5-py2.5.egg', '/usr/local/lib/python2.5/site-packages/Pygments-1.4-py2.5.egg', '/usr/local/lib/python2.5/site-packages/pytz-2010o-py2.5.egg', '/usr/local/lib/python2.5/site-packages/Trac-0.12.1-py2.5.egg', '/usr/local/lib/python2.5/site-packages/IniAdmin-0.2-py2.5.egg', '/usr/local/lib/python2.5/site-packages/TracAccountManager-0.2.1dev-py2.5.egg', '/usr/local/lib/python2.5/site-packages/MySQL_python-1.2.3-py2.5-freebsd-8.2-RELEASE-amd64.egg', '/usr/local/lib/python25.zip', '/usr/local/lib/python2.5', '/usr/local/lib/python2.5/plat-freebsd8', '/usr/local/lib/python2.5/lib-tk', '/usr/local/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/site-packages', '/usr/local/lib/python2.5/site-packages/PIL', '/usr/local/lib/python2.5/site-packages', '/home/casf58/www/site2/cgi-bin/']
Server time: Tue, 11 Jun 2013 20:52:41 +0400
This is the empty test project which works fine on local machine. But it doesn't work at hosting. Of course, I uncommented all the necessary lines in urls.py and setiings.py and checked it several times. If I comment them back, the Django Welcome page is displayed.
Still can't find a solution in google...
Python v.2.5. Project uses wsgi_mod.
Changes in settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
My urls.py:
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
r'^admin/', include(admin.site.urls)
)
You need to enclose your url pattern in ()
(r'^admin/', include(admin.site.urls)),
Try this:
urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)
Upon accessing the test server/weblog/ url on localhost, in an environment with "latest everything stable" (python 2.7, django 1.4.1, apache 2.2.22) I'm getting:
NoReverseMatch at /weblog/
Reverse for 'zinnia_entry_add' with arguments '()' and keyword arguments '{}' not found.
Request Method: GET
Request URL: http://127.0.0.1/weblog/
Django Version: 1.4.1
Exception Type: NoReverseMatch
Exception Value:
Reverse for 'zinnia_entry_add' with arguments '()' and keyword arguments '{}' not found.
Exception Location: /usr/local/lib/python2.7/dist-packages/django/template/defaulttags.py in render, line 424
Python Executable: /usr/bin/python
Python Version: 2.7.3
Excerpt from settings.py:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.staticfiles',
'django.contrib.admindocs',
'django.contrib.messages',
'django.contrib.comments',
'image_labeler',
'tagging',
'mptt',
'zinnia',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static',
'zinnia.context_processors.version',
)
and from urls.py:
urlpatterns = patterns('',
# Example:
# (r'^lastpixel/', include('lastpixel.foo.urls')),
# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
(r'^weblog/', include('zinnia.urls')),
(r'^comments/', include('django.contrib.comments.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^$', views.Index),
(r'^login/?$', views.Login),
(r'^logout/?$', views.Logout),
(r'^register/?$', views.Register),
(r'^i$', include('image_labeler.urls')),
(r'^i/', include('image_labeler.urls')),
(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': '/home/lastpixel/web/media', 'show_indexes': True}),
(r'^.*$', views.Index),
)
The application works otherwise (withouth the zinnia blog). Any idea what I might be doing wrong? Much appreciated!
I had a similar problem after updating zinnia.
This helped me out, although I didn't expect a solution in mysql:
First, edit /etc/my.conf
[client]
default-character-set=utf8
[mysqld]
default-character-set = utf8
skip-character-set-client-handshake
character-set-server = utf8
collation-server = utf8_general_ci
init-connect = SET NAMES utf8
Second, restart mysql
Taken from:
zinnia on github
It is likely that it is a namespace problem. In your error page, do you see the inline error highlight something that looks like {% block 'zinnia:zinnia_entry_add' %}? This is part of the zinnia name space, indicated by the zinnia: part of that definition. If you see something like this, you likely just need to add the correct namespace to your URLs:
urlpatterns = patterns('',
#.....
(r'^weblog/', include('zinnia.urls', namespace="zinnia")),
#.....
)