Error updating django 1.5 - u "'admin' is not a registered namespace - django

I am upgrading django from 1.4 to 1.5 in the front and all goes well, but admin side when I try to enter the url I get this particular error, and not how to fix it, any ideas?
error:
NoReverseMatch at /admin/
u"'admin" is not a registered namespace
Request Method: GET
Request URL: http://lmgsyco.com/admin/
Django Version: 1.4.1
Exception Type: NoReverseMatch
Exception Value:
u"'admin" is not a registered namespace
Exception Location: /usr/local/lib/python2.6/dist-packages/django/template/defaulttags.py in render, line 424
Python Executable: /usr/bin/python
Python Version: 2.6.6
Urls:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', web_page, name='web_page'),
url(r'^login/$', 'django.contrib.auth.views.login'),
url(r'^logout/$', cerrar_sesion, name='cerrar_sesion'),
# Admin:
url(r'^admin/', include(admin.site.urls)),
# Admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
)

I had a problem that seems related to this.
Your error is showing Django 1.4.1, while from your question you seem to be trying to use 1.5.
Check your PYTHONPATH with
env | grep PYTHONPATH
My guess is that you are pointing to the old version of Django somewhere. (In my case it was my .bashrc file. I had set up virtualenv to use Django 1.5, but .bashrc was pointing it to 1.4 , and this was getting put in first in the PYTHONPATH).

Related

django_select2 Caught NameError while rendering: name 'patterns' is not defined

I am using django_select2 with my mezzanine project.
As per doc i follow processes.
#step1 :
pip install django-select2
#Step2 :
url(r'^select2/', include('django_select2.urls')),
But when i reloaded my website i got error
TemplateSyntaxError at /admin/cms_shop/deliverymethod/200/
Caught NameError while rendering: name 'patterns' is not defined
Request Method: GET
Request URL: https://example.net/admin/cms_shop/deliverymethod/200/
Django Version: 1.3.1
Exception Type: TemplateSyntaxError
Exception Value:
Caught NameError while rendering: name 'patterns' is not defined
Exception Location: /home/django/cmsenv/lib/python2.6/site-packages/django_select2/urls.py in , line 5
Python Executable: /home/django/cmsenv/bin/python
Python Version: 2.6.5
Python Path:
['/home/django/core/python/cmsintegration',
'/home/django/cmsenv/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg',
'/home/django/cmsenv/lib/python2.6/site-packages/pip-0.8.3-py2.6.egg',
'/home/django/cmsenv/lib/python2.6/site-packages/paython-0.0.1-py2.6.egg',
'/home/django/cmsenv/lib/python2.6/site-packages/django_shop-0.0.11.dev0-py2.6.egg',
'/home/django/cmsenv/lib/python2.6/site-packages/django_recaptcha-0.0.6-py2.6.egg',
'/home/django/cmsenv/lib/python2.6',
'/home/django/cmsenv/lib/python2.6/plat-linux2',
'/home/django/cmsenv/lib/python2.6/lib-tk',
'/home/django/cmsenv/lib/python2.6/lib-old',
'/home/django/cmsenv/lib/python2.6/lib-dynload',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/home/django/cmsenv/lib/python2.6/site-packages',
'/home/django/cmsenv/lib/python2.6/site-packages/PIL']
Please help me what i am doing wrong.
my urls.py code is
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns("",
url(r'^admin/cms_shop/productimport/delete_selected/([\w]+)/$', delete_selected_import_view, name="cms_shop_delete_selected_import"),
url("^admin/", include(admin.site.urls)),
url(r'^select2/', include('django_select2.urls')),
)
in settting.py
INSTALLED_APPS = (
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.redirects",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.sitemaps",
"mezzanine.conf",
"mezzanine.core",
"mezzanine.blog",
"mezzanine.pages",
"mezzanine.generic",
"userapp",
"django_select2",
)
FYI, you have Django 1.3 and should consider upgrading to 1.5.
Have you tried
from django.conf.urls import patterns
You'll get this error if you are upgrading to Django 1.8 or above.
Here is the new way to do it without patterns:
https://docs.djangoproject.com/ja/1.9/releases/1.8/#s-django-conf-urls-patterns
urlpatterns = [
url('^$', views.myview),
url('^other/$', views.otherview),
]

Django-CMS Will not run, 404 Page Error on initial installation

I am following the tutorial here:
http://django-cms.readthedocs.org/en/2.4.0/getting_started/tutorial.html
I have python 2.7.2 installed and this is all in a virtualenv
my pip install list:
Django (1.5.1)
django-classy-tags (0.4)
django-cms (2.4.2)
django-filer (0.9.5)
django-mptt (0.5.2)
django-polymorphic (0.5.1)
django-reversion (1.7.1)
django-sekizai (0.7)
easy-thumbnails (1.3)
html5lib (1.0b2)
MySQL-python (1.2.4)
PIL (1.1.7)
six (1.3.0)
South (0.8.1)
wsgiref (0.1.2)
Project is named dcms and this folder has the contents
dcms manage.py media static
I have also included media and static folders in dcms because I was confused in which folders that they should be placed in
When I navigate to 127.0.0.1:8000 I see
Using the URLconf defined in dcms.urls, Django tried these URL patterns, in this order:
^media/(?P<path>.*)$
^static\/(?P<path>.*)$
^en-us/
The current URL, , didn't match any of these.
My urls file is a copy/paste of what is in the tutorial I posted above
from django.conf.urls.defaults import *
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings
admin.autodiscover()
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns
Initially I thought maybe it is not calling the +u urlpatterns part of the code for whatever reason, but even when I delete the if statement and just have it call urlpatterns directly in the top part I still don't get the pretty splash page that should come up
any thoughts?
I wouldn't worry about i18 at this point.
Try using the regular patterns. Add this import:
from django.conf.urls import patterns
and replace i18n_patterns with regular old patterns.
Did you create a page?
Can you get to Admin? if so go into it and create a page at /

cannot import name admin

I am new at Django. I am trying to create basic admin panel. when I changed the urls.py file and I put url(r'^admin/', include(admin.site.urls)), into patterns then it gave error like that:
Request Method: GET return
Request URL: http://127.0.0.1:8000/
Django Version: 1.4
Exception Type: ImportError
Exception Value:cannot import name admin
Exception Location:/home/ulascan/Desktop/projects/purple/purple/urls.py in <module>, line 1
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:
['/home/ulascan/Desktop/projects/purple',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2'
...
...]
Make sure that in your settings.py you have django.contrib.admin, uncommented in INSTALLED_APPS. And also check that you have these lines in your urls.py:
from django.contrib import admin
admin.autodiscover()

django cms apphook error

I am learning django-cms. I tried to make custom plugin which was quite successful but when I tried to hook my custom made plugin to apphook, its giving me an error, saying,
No Module named urls
.
I followed the tutorial which was given in django cms sites documentation, and created the cms_app.py file. Currently my application directory has all the files which is required to make a custom plugin for django cms, and an additional file of cms_app.py.
Is something wrong with setting of the url or do I need to create a new urls.py file inside my app directory?
My cms_app.py is exactly the same as given in the tutorial.
i have created a project called myproject using command -
python django-admin.py startproject
myproject
After referring to the tutorial given for cms I created a plugin called first, using the basic command
python manage.py startapp first
Now the plugin is working perfectly well, and the directory structure before making an attempt to the apphook was,
first/
__init__.py
cms_plugins.py
models.py
tests.py
views.py
Now after making an attempt to hook the app in apphook, the directory structure is:
first/
__init__.py
cms_app.py
cms_plugins.py
models.py
tests.py
views.py
My cms_app.py is as follows:
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
class FirstApp(CMSApp):
name = _("First App") # give your app a name, this is required
urls = ["first.urls"] # link your app to url configuration(s)
apphook_pool.register(FirstApp) # register your app
i have a urls.py file in myproject folder, and it is as follows:
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'myproject.views.home', name='home'),
# url(r'^myproject/', include('myproject.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)),
url(r'^', include('cms.urls')),
)
if settings.DEBUG:
urlpatterns = patterns('',
(r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')),
) + urlpatterns
I have restarted the server as was mentioned in the tutorial, but no success.
Any ideas as to what is wrong with my simple app?!
EDIT - 1
My views file is as follows:
from django.http import HttpResponse
def index(request):
“””Generate the context for the main summary page”””
return render_to_response(‘first/first.html’)
Edit - 2
I have changed my urls.py inside first app folder to this :
from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'myproject.views.home', name='home'),
# url(r'^myproject/', include('myproject.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)),
url(r'^first/$', include('first.views.index')),
)
if settings.DEBUG:
urlpatterns = patterns('',
(r'^' + settings.MEDIA_URL.lstrip('/'), include('appmedia.urls')),
) + urlpatterns
But now I am getting this error:
SyntaxError at /
Non-ASCII character '\xe2' in file /home/naveen/django_projects/myproject/first/views.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (views.py, line 4)
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.3
Exception Type: SyntaxError
Exception Value:
Non-ASCII character '\xe2' in file /home/naveen/django_projects/myproject/first/views.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details (views.py, line 4)
Exception Location: /usr/local/lib/python2.6/dist-packages/django/utils/importlib.py in import_module, line 35
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/naveen/django_projects/myproject',
'/usr/local/lib/python2.6/dist-packages/pip-0.8.3-py2.6.egg',
'/usr/local/lib/python2.6/dist-packages',
'/usr/local/lib/python2.6/dist-packages/django_evolution-0.6.2-py2.6.egg',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/python2.6/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.6/gtk-2.0']
Server time: Thu, 31 Mar 2011 11:00:41 -0500
I have edited the urls and views but now I am getting this error.
NameError at /first/
global name 'render_to_response' is not defined
Request Method: GET
Request URL: http://localhost:8000/first/?preview
Django Version: 1.3
Exception Type: NameError
Exception Value:
global name 'render_to_response' is not defined
Exception Location: /home/naveen/django_projects/myproject/first/views.py in index, line 5
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path:
['/home/naveen/django_projects/myproject',
'/usr/local/lib/python2.6/dist-packages/pip-0.8.3-py2.6.egg',
'/usr/local/lib/python2.6/dist-packages',
'/usr/local/lib/python2.6/dist-packages/django_evolution-0.6.2-py2.6.egg',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload',
'/usr/local/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages',
'/usr/lib/python2.6/dist-packages/PIL',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6',
'/usr/lib/python2.6/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.6/gtk-2.0']
Server time: Thu, 31 Mar 2011 14:50:32 -0500
You do not have a first.urls module with the URLs of your 'first' app. Next to your file first/models.py, create a file first/urls.py which contains the URL patterns for the 'first' app.
For the views you give in your questions, the urls.py should look something like this:
from django.conf.urls.defaults import *
from first.views import index
urlpatterns = patterns('',
url(r'^$', index),
)
Also note that in your views, you use non-standard quote characters, it should look like this:
from django.http import HttpResponse
def index(request):
"""Generate the context for the main summary page"""
return render_to_response("first/first.html")

Django Template Issue

I am following along on this tutorial, after I add the templates and put the pattern in urls.py, I go the website I get a template not loaded page.
This is my template dirs section from settings.py:
TEMPLATE_DIRS = (
"/home/django-projects/base/templates/",
)
the base folder hierarchy is this:
blog<dir>
dbs<dir>
__init__.py
manage.py
settings.py
templates<dir>
urls.py
urls.py looks like this:
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('base.blog.views',
(r"", "main"),
# Example:
# (r'^base/', include('base.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)),
)
In templates I have a folder called blog, and it contains the two html files from the tutorial. I am just not sure what setting I am missing to display the proper templates. I will be happy to post anything else you would need to see. I am sure it is something trivial, I just can't seem to figure out what it is. Thanks for your help.
EDIT
So I was playing around with it, and I realized I couldn't get to admin. So I uncoupled the urls for the blog part away from the main. The urls.py on the top level looks like this:
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'blog/', include('blog.urls')),
# Example:
# (r'^base/', include('base.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)),
)
And in the blog folder urls.py looks like this:
from django.conf.urls.defaults import *
urlpatterns = patterns('base.blog.views',
(r'^$', 'main'),
)
Now I can get to admin, but still get a template load error when I try to get to the blog.
TemplateDoesNotExist at /blog/
blog/list.html
Request Method: GET
Request URL: http://192.168.1.124:9999/blog/
Django Version: 1.2.3
Exception Type: TemplateDoesNotExist
Exception Value:
blog/list.html
Exception Location: /usr/local/lib/python2.6/dist-packages/Django-1.2.3-py2.6.egg/django/template/loader.py in find_template, line 138
Python Executable: /usr/bin/python
Python Version: 2.6.6
Python Path: ['/home/kevin/django-projects/base', '/usr/local/lib/python2.6/dist-packages/setuptools-0.6c11-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/BeautifulSoup-3.1.0.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/Django-1.2.3-py2.6.egg', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/local/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages', '/usr/lib/python2.6/dist-packages/PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/pymodules/python2.6/gtk-2.0']
Server time: Tue, 2 Nov 2010 11:59:13 -0500
Template-loader postmortem
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.Loader:
Using loader django.template.loaders.app_directories.Loader:
Should the last line of the "main" view contain "blog/list.html" instead of "list.html"?
Try replacing that line with the following:
return render_to_response("blog/list.html", dict(posts=posts, user=request.user))
Do the same thing with the "post" view.
Basically, Django is going to look under each of the configured template directories in settings.py and if you specify "list.html" it better be in the root of of of those directories. Since you put the "list.html" in the "blog" sub-directory and not where you told it to look, Django can't find it.
First, you have a missing leading / in your template directory:
TEMPLATE_DIRS = (
"/home/django-projects/base/templates/",
)