Django bug : ImproperlyConfigured at /databrowse/ . How to solve this bug? - django

My urls.py of the project looks like this
from django.conf import settings
from django.conf.urls.defaults import *
from django.contrib import admin
from django.contrib import databrowse
from world.views import welcome
admin.autodiscover()
urlpatterns = patterns('',
(r'^$', welcome),
(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^databrowse/', include(databrowse.site.root)),
)
urlpatterns += patterns('',
(r'^media/$',include('django.views.static.serve'),{'document_root': settings.MEDIA_ROOT, 'show_indexes': True})
)
What changes have to be done for this to work ?

The only change you have to make is to follow the actual documentation. The documentation doesn't use include for databrowse.

Related

Redirect to custom 404 html page in DjangoCMS

How can I redirect the user to my custom 404.html page if he enters a wrong path ?
views.py:
from django.shortcuts import render, render_to_response, redirect
from django.template import RequestContext
import threading
def url_redirect(request):
return render_to_response('blog.html', RequestContext(request))
def post_redirect(request):
return render_to_response('post.html', RequestContext(request))
def privacy_redirect(request):
return render_to_response('privacy.html', RequestContext(request))
def terms_conditions_redirect(request):
return render_to_response('terms.html', RequestContext(request))
def page_404(request):
return render_to_response('404.html', RequestContext(request))
urls.py:
from __future__ import print_function
from cms.sitemaps import CMSSitemap
from django.conf.urls import *
from django.conf.urls.i18n import i18n_patterns
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib import admin
from django.conf import settings
from django.conf.urls import patterns
admin.autodiscover()
urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
url(r'^select2/', include('django_select2.urls')),
url(r'^blog', "website.views.url_redirect", name="url-redirect"),
url(r'^post', "website.views.post_redirect", name="post-redirect"),
url(r'^privacy', "website.views.privacy_redirect", name="privacy-redirect"),
url(r'^terms', "website.views.terms_conditions_redirect", name="terms_conditions-redirect"),
url(r'^404', "website.views.page_404", name="page_404"),
url(r'^', include('cms.urls')),
)
# This is only needed when using runserver.
if settings.DEBUG:
urlpatterns = patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
) + staticfiles_urlpatterns() + urlpatterns
I also have TEMPLATE_DEBUG = True and DEBUG = False in my settings.py file. Any help, please ?
Also, can you guys tell me if those methods from views.py are ok or if they could be rewritten in a better way ?
Thanks
add 404.html near base.html (main folder templates)
and when there is an error 404 , Django itself take your 404 page
in settings.py
DEBUG = False
TEMPLATE_DEBUG = True
ALLOWED_HOSTS = ['yourweb.com']

what's wrong with my urls.py in this example?

I just installed userena, and had the example working from the tutorial, but as soon as I added in a single line in URLS.py, I'm getting an error. In the example below, I added the line mapping the home function from views.py
Now the issue I'm having is that when I go to 127.0.0.1/8000, I get TypeError: string is not callable, but then oddly, if I go to accounts/signup or accounts/signin, I am getting the template that should be appearing if i go to 127.0.0.1/8000.
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.views.generic import TemplateView
from accounts import views
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r"^$", 'home'),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('userena.urls')),
)
Here is my accounts/views.py
from django.shortcuts import render
from django.http import HttpResponseRedirect
def home(request):
return render('homepage.html')
You need to remove the quotes in the url and import that view
from accounts.views import home
urlpatterns = patterns('',
url(r"^$", home),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('userena.urls')),
)
You can steel use the strings in the url() but you must use the format 'app.views.viewname'
urlpatterns = patterns('',
url(r"^$", 'accounts.views.home'),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('userena.urls')),
)
Or name the module in the first argument as string to patterns()
urlpatterns = patterns('accounts.views',
url(r"^$", 'home'),
url(r'^admin/', include(admin.site.urls)),
(r'^accounts/', include('userena.urls')),
)
the issue was I forgot to include the request in the return render.
The correct answer is that render is being called incorrectly. Actually, the views.py file would raise a SyntaxError, but we'll let that slide :)
# views.py
from django.shortcuts import render
def home(request):
return render(request, 'homepage.html')

Django: 404 error in urls.py

I have two urls.py files.
In project/urls.py:
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
In project/blog/urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('blog.views',
(r'^$', 'index'),
(r'^(?P<slug>[a-z-]+)/$', 'detail'),
(r'^(?P<slug>[a-z-]+)/comment/$', 'comment'),
)
Then I tried to browse these URLs:
http://127.0.0.1:8888/ (404)
http://127.0.0.1:8888/hello-world/ (404)
http://127.0.0.1:8888/admin/ (It worked)
Django version: 1.4 pre-alpha SVN-16985.
Thanks!
To fix the http://127.0.0.1:8888/ error, change your regular expression to:
(r'^$', include('blog.urls')),
Regarding the http://127.0.0.1:8888/hello-world/ error: There could be many things causing this. First, check that you have a blog title that actually returns the slug 'hello-world'.

NameError:Admin not found in django

The urls.py of the project is this
from django.conf.urls.defaults import patterns, include, url
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'Sdr.views.home', name='home'),
# url(r'^Sdr/', include('Sdr.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)),
(r'', include('Sdr.sdr.urls')),
)
The urls.py of the app looks like this
# Import django modules
from django.conf.urls.defaults import *
from django.contrib import admin
# Import custom modules
import settings
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
(r'', include('Sdr.sdr.urls')),
)
The error I am getting is exception found is
Django Version: 1.3
Exception Type: NameError
Exception Value:
name 'admin' is not defined
You forgot to import admin in the project's urls.py. Read harder.
Uncomment the following in your project's urls.py.
from django.contrib import admin
admin.autodiscover()
Faced with the same problem in tutorial.
Try to add in models.py:
from django.contrib import admin

Django cannot find admin.sites.url

I am developing a django site locally using rc1.3 and after making several adjustments to my urls.py file i am receiving error messages that django cannot import admin.site.urls. by urls.py file is below.
urlpatterns = patterns('',
# Example:
(r'^city/$', 'venue.views.city_index'),
(r'^accounts/', include('registration.urls')),
(r'^accountss/', include('registration.backends.simple.urls')),
(r'^profiles/', include('profiles.urls')),
(r'^admin/', include('admin.site.urls')),
(r'^city/(?P<city>[-\w]+)/$', 'venue.views.city_detail'),
(r'^city/(?P<city>[-\w]+)/venue/$', 'venue.views.venue_index'),
)
Any idea what might be cause this, thanks.
http://docs.djangoproject.com/en/dev/intro/tutorial02/#activate-the-admin-site
Don't include the string path, actually import the admin module and point to its urls.
from django.contrib import admin
urlpatterns += patterns('',
(r'^admin/', include(admin.site.urls)),
)