Page Not Found error - django

Why I get this error?
Page not found (404)
Using the URLconf defined in myproject.urls, Django tried these URL patterns, in this order:
^admin/doc/
^admin/
The current URL, , didn't match any of these.
I just uncomment the related lines in urls.py to enable admin and admindoc. They both work; but when I go to the root domain (e.g. example.com), I get this error.
my urls.py is like this:
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^myproject/', include('myproject.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'^admin/', include(admin.site.urls)),
)
Thanks in advance...

That's because you don't have a URL defined for the root domain. Check our URLconf: it contains the two lines you listed, which means that you only have URLs defined for example.com/admin and example.com/admin/doc, but not just example.com.

Related

Django - Page not found (404) for URL

I am getting the following error when ever I access the url's except /home.
Page not found (404)
Request Method: GET Request URL
Using the URLconf defined
in report_ui.urls, Django tried these URL patterns, in this order:
^admin/
^home/
The current URL, individual/, didn't match any of
these. You're seeing this error because you have DEBUG = True in your
Django settings file. Change that to False, and Django will display a
standard 404 page.
The code :
urls.py
# -*- coding: utf-8 -*-
from django.conf.urls import patterns, url
urlpatterns = patterns('dnslog.views',
# Examples:
url(r'$', 'home'),
url(r'^report/$', 'report'),
url(r'^angular/$', 'angular'),
url(r'^linear/$', 'LinearPrediction'),
url(r'^splunk/$', 'splunkdata'),
url(r'^toyprediction/$', 'toyprediction'),
url(r'^saleprediction/$', 'GetSalesPrediction'),
url(r'^customerprediction/$', 'GetCustomerPrediction'),
url(r'^monthwiseprediction/$', 'GetMonthWiseSalesPrediction'),
url(r'^getlinearprediction/(?P<duration>.\w+)/$', 'GetLinearPrediction'),
url(r'^getprediction/$', 'GetPredictionReport'),
url(r'^modeldata/(?P<obj>.\w+)/$', 'GetConsolidatedObjectData'),
# url(r'^modeldata/(?P<date>\d{4}-\d{2}-\d{2})/$', 'GetConsolidatedObjectData'),
url(r'^home/(?P<date>\d{4}-\d{2}-\d{2})/$', 'GetConsolidateHits'),
url(r'^bytes/$', 'BytesDownload'),
url(r'^BytesDownload/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetConsolidateDownloadBytes'),
url(r'^getCntPerData/$', 'GetConsolidateCntPer'),
url(r'^help/$', 'help'),
url(r'^individualhits/$', 'individualhits'),
url(r'^individualhits1/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualHits'),
url(r'^bubble/$', 'bubble'),
url(r'^bubblechart/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetConsolidateHitsForBubble'),
#url(r'^test/$', 'test'),
url(r'^domaincloud/$', 'cloud'),
url(r'^getdomaincloud/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getclouddata'),
url(r'^circleview/$', 'circle'),
url(r'^getcircleview/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcircledata'),
url(r'^comparisionview/$', 'comparision'),
url(r'^getcomparision/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcomparisiondata'),
url(r'^individualcomparision/(?P<domain>.+)/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualComparisonData'),
url(r'^trendview/$', 'trend'),
url(r'^gettrendview/$', 'Gettrenddata'),
url(r'^zoomabletree/$', 'zoomabletree'),
url(r'^getzoomabletree/(?P<date>\d{4}-\d{2}-\d{2})/$', 'Getcircledata'),
##url(r'^report_ui/', include('report_ui.foo.urls')),
#url(r'^individualConsolidatedHits/$', 'individualConsolidatedHits'),
url(r'^getConsolidatedCategoryDetails/(?P<date>\d{4}-\d{2}-\d{2})/$',
'getConsolidatedCategoryDetails'),
# overall individual reports
url(r'^individual/$', 'individual'),
## individual Category report
#url(r'^individualcategory/$', 'individualcategory'),
url(r'^GetIndividualCategory/(?P<empid>.+)/(?P<date>\d{4}-\d{2}-\d{2})/$',
'GetIndividualCategory'),
url(r'^twitter/$','twitter'),
root urls.py
from django.conf.urls import patterns, include, url
# to include the media url
from django.conf import settings
from django.conf.urls.static import static
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'report_ui.views.home', name='home'),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^home/', include('dnslog.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
)
Any help would be appreciated. Thanks!
Either change your root urls.py
url(r'^home/', include('dnslog.urls')),
to:
url(r'^/', include('dnslog.urls')),
Or change your request from
from:
individual/
to:
/home/individual

Django admin panel works but main page gives me a 404

I'm brand new to Django and Python. I've only done php.
It took me three tries, but I've almost Django installed correctly. I followed the tutorial on installing it, and it worked. So I enabled the admin, panel, and set up mysql.
The admin panel works, and I've got my static folder so it has all of the css as well. But when I go to the main page I get this 404. (My project is called firstweb) So whenI go into firstweb there is a 404, but firstweb/admin works.
Using the URLconf defined in firstweb.urls, Django tried these URL patterns, in this order:
1. ^admin/
The current URL, firstweb/, didn't match any of these.
And I'm confused by the whole runserver thing. Is that some other little server other than my Apache? Why do I need to start it every time?
from django.conf.urls 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'^$', 'firstweb.views.home', name='home'),
# url(r'^firstweb/', include('firstweb.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)),
)
It looks like your url conf does not include any url pattern for any other pages accept the admin.
If you want the root url to display a page, uncomment this line
url(r'^$', 'firstweb.views.home', name='home'),
And then make sure that in firstweb/views.py you have a view function called 'home', which I assume is part of the tutorial.

Django admin login with credentials in URL

I am a newbie in Django. Basically what I am looking for is - I want users to click on a link and login into the admin site. Can the parameters be passed in the URL itself ?
Please help.
You can write your own view on your website that will:
get the credentials from your URL
authentificate the user using authenticate and login functions from django.contrib.auth (see https://docs.djangoproject.com/en/dev/topics/auth/default/#auth-web-requests)
and then redirect your user to the admin URL using django redirect function (see https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#redirect)
Register Your admin panel with django . https://docs.djangoproject.com/en/1.3/intro/tutorial02/#activate-the-admin-site
Change your urls.py like
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# 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)),
)
Give the href as Click
You are done

django gets a 404 page when I try to access django-registration

Hello and thank you in advance,
When I installed django-profiles and django-registration. I believe I followed a tutorial correctly on how to configure them:
http://agiliq.com/books/djenofdjango/chapter5.html#reusable-apps
Now when I try to access website.com/accounts I get a 404 page:
Using the URLconf defined in acme_p.urls, Django tried these URL patterns, in this order:
^$
^accounts/
^admin/doc/
^admin/
The current URL, accounts, didn't match any of these.
My urls files look like this:
#acme_p urls - Django Project
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', include('user_prof.urls')),
# Examples:
# url(r'^$', 'acme_p.views.home', name='home'),
# url(r'^acme_p/', include('acme_p.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)),
)
user_prof urls.py - Django App one level below project mentioned above
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^login/$', 'auth.views.login_user'),
(r'^accounts/', include('registration.urls')),
# (r'^accounts/', include('registration.backends.default.urls')),
)
Thank you for you help.
dp
(r'^accounts/', include('registration.urls')), should be in the root urls.py not the app urls.py
There is no website.com/account in the configuration, there is only website.com/account/(more) where (more) has the rest of the url that is given to the django-registration module. You could try website.com/account/login/ for example to check if the django-registration module is working.
Also you should just put those on the root urls.py file.

Django-tagging: Grabbing objects by specifying multiple tags?

I currently have an entry in urls.py which fetches lone permalinks for my bugs:
from django.conf.urls.defaults import *
from tagging.views import tagged_object_list
from bugs.models import Bug
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Example:
# (r'^workarounds/', include('workarounds.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')),
(r'^$', 'django.views.generic.simple.direct_to_template', {'template':'homepage.html'}),
(r'^bugs/(?P<slug>[-\w]+)/$', 'bugs.views.bug_detail'),
(r'^bugs/tagged/(?P<tag>[^/]+)/$',
'tagging.views.tagged_object_list',
{
'queryset_or_model': Bug,
'template_name' : 'tag/lone.html'}),
# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
)
So if I specified a url of say, bugs/tagged/firefox it would bring up firefox tags. How could I make it filter out by multiple tags? eg: firefox+css would return all objects tagged with firefox and css.
You'll have to build your own view instead of using tagging.views.tagged_object_list.
(r'^bugs/tagged/(?P<tags>[-\w+]+)/$', your_tag_view)
In your view, get a list of the tags you are searching for:
tags = tags.split('+')
Then, use the TaggedItem.objects.get_by_model query, which conveniently will accept a list of tags:
from tagging.models import TaggedItem
bugs = TaggedItem.objects.get_by_model(Bug, tags)