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)),
)
Related
I am modifying Gitstack, a 32bit Python2.7-based Git Web Application (available here) for my 64bit Python installation.
In the process, I also had to modify all the Django codes e.g. urlpatterns, etc.
While I managed to adapt it to my Apache/PHP environment, I ended up with this Django issue.
The error is as below while trying to access /gitstack location
TypeError at /registration/login/
sequence item 0: expected string or Unicode, function found
Request Method: GET
Request URL: https://localhost/registration/login/?next=/gitstack/
Django Version: 1.11.6
Exception Type: TypeError
Exception Value:
sequence item 0: expected string or Unicode, function found'
I could not make any useful insight from the traceback below with my little head. The traceback just ends inside Django which seems very little helpful.
Environment:
Request Method: GET
Request URL: https://localhost/registration/login/?next=/gitstack/
Django Version: 1.11.6
Python Version: 2.7.13
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'gitstack')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\exception.py" in inner
41. response = get_response(request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in _legacy_get_response
249. response = self._get_response(request)
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in _get_response
172. resolver_match = resolver.resolve(request.path_info)
File "C:\Python27\lib\site-packages\django\urls\resolvers.py" in resolve
366. sub_match = pattern.resolve(new_path)
File "C:\Python27\lib\site-packages\django\urls\resolvers.py" in resolve
201. return ResolverMatch(self.callback, args, kwargs, self.name)
File "C:\Python27\lib\site-packages\django\urls\resolvers.py" in __init__
55. self.view_name = ':'.join(self.namespaces + [view_path])
Exception Type: TypeError at /registration/login/
Exception Value: sequence item 0: expected string or Unicode, function found
Below is my modified app\urls.py:
from django.conf.urls import url, include
from django.contrib.auth.views import login
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = [
# Examples:
#url(r'^$', 'app.views.home', name='home'),
# url(r'^app/', include('app.foo.urls')),
# login
url(r'^registration/login/$', login, name=login),
# 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)),
url(r'^gitstack/', include('gitstack.urls')),
# url(r'^rest/', include('rest.urls')),
]
Here is my modified gitstack/urls.py
from django.conf.urls import url, include
from .views import index, users, groups, repository_permission, add_repo_user_dialog, add_repo_group_dialog, group_user, add_group_user_dialog, settings_general, settings_authentication, settings_security, log_me_out
urlpatterns = [
# standard user interface
url(r'^$', index, name='index'),
url(r'^users/', users, name='users'),
url(r'^groups/', groups, name='groups'),
url(r'^repository/(?P<repo_name>.+)/permission/$', repository_permission, name='repository_permission'),
# add users dialog
url(r'^repository/(?P<repo_name>.+)/permission/adduser/$', add_repo_user_dialog, name= 'add_repo_user_dialog'),
url(r'^repository/(?P<repo_name>.+)/permission/addgroup/$', add_repo_group_dialog, name='add_repo_group_dialog'),
url(r'^group/(?P<group_name>.+)/user/$', group_user, name='group_user'),
# add users dialog (for the group)
url(r'^group/(?P<group_name>.+)/user/add/$', add_group_user_dialog, name='add_group_user_dialog'),
# settings tab
url(r'^settings/general/', settings_general, name='settings_general'),
url(r'^settings/authentication/', settings_authentication, name='settings_authentication'),
url(r'^settings/security/', settings_security, name='settings_security'),
url(r'^logout/', log_me_out, name='log_me_out'),
]
urlpatterns should be a Python list of url() instances. So you need to remove 'gitstack.views', from urlpatterns in gitstack/urls.py
UPD
Also you have problem with login pattern. Name should be string. Change url(r'^registration/login/$', login, name=login) to url(r'^registration/login/$', login, name='login')
I have created a DJango project in eclipse. Later i added a new application (R-CLick Project folder ---> DJANGO ---> Create application (manage.py startapp))
I names it Super.
Then again i created another new application (using the same steps described above), and named it Human.
In my project now, i have 2 applications created (In eclipse it appears as 2 packages).
I have a file called admin.py inside the package Super.
The code is as follows:
from django.contrib import admin
from Super.models import People
from Human.models import NormalHuman
admin.site.register(People)
admin.site.register(NormalHuman)
I even registered the 2 new applications in the Settings.py file.
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'Super',
'Human',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
I also made changes to the urls.py file.
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
from Human.models import NormalHuman
admin.autodiscover()
urlpatterns = patterns('',
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^normal/', NormalHuman),
)
Problems i want to solve:
1.) After restarting the server, when i try to navigate to the url 127.0.0.1:9095/normal i end up in a 404
2.) I need to add NormalHuman to the admin page, so i have access to its content.
You have already registered admin url so you do not need to add
url(r'^normal/', NormalHuman),
to see content of NormalHuman model.
just simply hit 127.0.0.1:9095/admin/human/normalhuman to see content of NormalHuman model.
I am getting an import error on a very basic test site I am trying. Below is the error message:
ImportError at /
No module named tickets
Request Method: GET
Request URL: http://dcdev1.dcevolve.com/
Django Version: 1.5.1
Exception Type: ImportError
Exception Value:
No module named tickets
Exception Location: /usr/lib/python2.6/site-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/django/dcdev1',
'/usr/lib64/python26.zip',
'/usr/lib64/python2.6',
'/usr/lib64/python2.6/plat-linux2',
'/usr/lib64/python2.6/lib-tk',
'/usr/lib64/python2.6/lib-old',
'/usr/lib64/python2.6/lib-dynload',
'/usr/lib64/python2.6/site-packages',
'/usr/lib/python2.6/site-packages']
Server time: Mon, 5 Aug 2013 02:58:39 -0500
My directory structure is this:
-/home/django/dcdev1
-/home/django/manage.py
-/home/django/tickets
Under dcdev1 there are __init__.py __init__.pyc settings.py settings.pyc urls.py urls.pyc wsgi.py wsgi.pyc
Under tickets there are
__init__.py __init__.pyc models.py models.pyc templates tests.py views.py views.pyc
Relevant settings.py sections:
TEMPLATE_DIRS = (
"tickets/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',
'tickets',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
urls.py:
from django.conf.urls import patterns, include, url
from tickets.models import ticket_info
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'dcdev1.tickets.views.home', name='home'),
# url(r'^dcdev1/', include('dcdev1.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)),
models.py:
from django.db import models
class ticket_info(models.Model):
from_address = models.CharField(max_length = 30)
to_address = models.CharField(max_length = 30)
subject_id = models.CharField(max_length = 100)
body_text = models.TextField()
recv_timestamp = models.DateTimeField()
views.py
from django.shortcuts import render_to_response
from tickets.models import ticket_info
def home(request):
return render_to_response('index.html')
I am working off of the guide at http://net.tutsplus.com/tutorials/python-tutorials/python-from-scratch-creating-a-dynamic-website/
There seems to be some differences in his directory structure vs mine. I'm guessing something had changed in later django versions. I have never used django, just trying it out to see if it will work for a project. Any help would be much appreciated.
In urls.py
try these
url(r'^$', 'tickets.views.home', name='home'),
instead of these
url(r'^$', 'dcdev1.tickets.views.home', name='home'),
Also you can run python manage.py validate and maybe you will see something useful.
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
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")),
#.....
)