404 when enabling admin with Django - python

I had correctly configured a Django app and had it running smoothly. However, when I went to enable the administration panel, I encountered a 404 error upon uncommenting this line:
url(r'^admin/', include(admin.site.urls))
Upon trying to access my site, I received this:
Using the URLconf defined in cms.urls, Django tried these URL patterns, in this order:
1. ^admin/
The current URL, , didn't match any of these.
I can't figure out how to get around this error. Does anyone with some Django experience have a solution? Thanks!
EDIT: Here is the entire urls.py file:
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'^$', 'cms.views.home', name='home'),
# url(r'^cms/', include('cms.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)),
)

Have you tried, http://yourdomain:port/admin ? If you are using the default url, I would try
http://127.0.0.1:8000/admin

Related

The included urlconf doesn't have any patterns in it + django

I have been trying out the django tutorial and stuck with this error. I am in the 3rd page of the tutorial and everything was going good until i encountered this error Django Tutorial. I was following the exact steps in the tutorial. This is the error i got
ImproperlyConfigured at /polls
The included urlconf <module 'polls.urls' from 'C:\\Python34\\mysite\\polls\\urls.py'> doesn't have any patterns in it
I am pasting my code here.
ROOT_URLCONF = 'mysite.urls'` in settings.py,
from django.conf.urls import patterns, url
from polls import views
urlpattern = patterns('',
url(r'^$',views.index,name='index')
)`
inside MYSITE/POLLS/URLS.PY
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^polls/', include('polls.urls')),
url(r'^admin/', include(admin.site.urls)),
)
INSIDE MYSITE.URLS.PY
Sorry if i missed out anything that i had to mention to get a clear picture. Any help would be appreciated.
The first file has urlpattern instead of urlpatterns.

How do I set my django view's URL to the root domain of my website?

I'm hosting my Django app on Heroku and my domain name is registered with Network Solutions. When I enter my domain name, i.e. www.example.com, Heroku displays:
"Not Found
The requested URL / was not found on this server."
I then have to navigate to the template's URL that displays my app's landing page, www.example.com/shipment/.
How can I get my root domain www.example.com to automatically redirect to www.example.com/shipment/, or alternatively, change the URL of /shipment/ to my root domain?
Here's the urls.py for my app:
from django.conf.urls import patterns, url
from shipment import views
urlpatterns = patterns('',
url(r'^$', views.landing, name='landing'),
url(r'^create-subscription/$', views.createSubscription, name='createSubscription'), #
url(r'^(?P<subscription_duration>\d+)/create-account/$', views.createAccount, name='createAccount'),
url(r'^create-account/pay/$', views.pay, name='pay'),
url(r'^create-account/confirm/$', views.confirm, name='confirm'),
)
Here's the urls.py for my project:
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'^$', 'subscription.views.home', name='home'),
# url(r'^subscription/', include('subscription.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'^shipment/', include('shipment.urls', namespace = "shipment")),
url(r'^admin/', include(admin.site.urls)),
)
I changed:
url(r'^shipment/', include('shipment.urls', namespace = "shipment")),
to
url(r'^', include('shipment.urls', namespace = "shipment")),
and that fixed it!
Your problem is this line:
url(r'^shipment/', include('shipment.urls', namespace = "shipment")),
It means "include all these URLs but they must start with "shipment/".
You could add a line to your site's urls.py like:
url(r'^$', generic.RedirectView(url='/shipment/', permanent=False)),
(and then also put a corresponding "from django.views import generic" at the top of your file).
This map your URL / to a redirect view that redirects to /shipment/.

Page not found (404) in django tututorial

I'm working through https://docs.djangoproject.com/en/1.4/intro/tutorial02/ .
after changing the urls.py to
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'^$', '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)),
)
I get the following when I start the runserver:
404 error
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
The current URL, , didn't match any of these.
Is there anything obvious that I'm doing wrong?
Thanks in advance,
Bill
You don't have a base url defined. You need something like -
urlpatterns = patterns('',
# ...
url(r'^$', HomeView.as_view())
)
You should be able to see your site at - localhost:8000/admin/ (assuming you're running your dev server with python manage.py runserver).
Django checks all the URL's you've defined in your url conf file and looks for one that matches the url you've entered in the browser. If it finds a URL that matches then it serves up the http response returned by the url's corresponding view (HomeView in the code above). The urls.py file is matching url's to views. Views return the http response.
Looking at the error message you've got (and the code you've included from the url.py file), you can see that there's only one url defined in your app - admin/. Trying to get a page at any other url will fail.
For more information have a look at the docs for django's URL Dispatcher.

django urlpatterns order

I ran into a problem loading the admin section of my django site with the following error:
No FlatPage matches the given query.
I managed to solve the problem, but I'm attempting to understand why it solved the problem. In my urls.py file, I moved the url(r'', include('django.contrib.flatpages.urls')), after the url(r'^admin/', include(admin.site.urls)), and voila, it worked. Can someone explain, briefly, why this would make a relevant difference? Should the admin url always be at the top of the list?
Code the produced the error:
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'mysite.views.home', name='home'),
# url(r'^mysite/', include('mysite.foo.urls')),
url (r'^blog/', include('blog.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'', include('django.contrib.flatpages.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
)
This is django 1.4.
The problem is that you have not installed the flatpages application correctly. Django's flatpages application relies on a piece of middleware that intercepts 404 requests. As a result, you do not need to add django.contrib.flatpages.urls to your urls.py.
You received that error because the regex you are using ('') matches all URLs. As a result, the urlpattern never reached ^admin/'.

django 1.3 admin problem

everytime i click on any link in django admin, it will call other urls too, and log me out, so now i can't change anything.
session id is changed everytime too.
i've checked urls.py and the admin ones are at the top of the file.
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'developer.views.home', name='home'),
# url(r'^developer/', include('developer.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)),
)

Categories

Resources