Some of my django urls will not work. I can visit my index page and the django admin page just fine. I can log in and create objects no problem. For example, I can create a site, like below, but when I try to visit the collection of sites, I get hit with a 404 (even after creating one). I'm using Django allauth as well, and those pages are also having troubles with my urlconf. Can anyone spot the error?
For example, this url:
Page not found (404)
Request Method: GET
Request URL: http://myapp.com/admin/sites/site/
No reward found matching the query
And this one:
Page not found (404)
Request Method: GET
Request URL: http://shielded-island-1440.herokuapp.com/accounts/profile/
Using the URLconf defined in litherewards.urls, Django tried these URL patterns, in this order:
^ ^$ [name='index']
....
^ ^reward/$ [name='reward_list']
^ ^redeem/(?P<reward_code>)/$ [name='redeem_reward']
^ ^redeem/(?P<slug>\w+)/(?P<reward_code>\w+)/$ [name='reward_confirmation']
....
^account/
^sitemap\.xml$
^admin/
My urlconf is as follows:
from django.conf.urls import patterns, include, url
from myapp.views import RewardSitemap
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
admin.autodiscover()
sitemaps = {'rewards':RewardSitemap}
urlpatterns = patterns('',
url('^', include('myapp.urls', namespace="fluffy")),
url(r'^account/', include('allauth.urls')),
url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps}),
url(r'^admin/', include(admin.site.urls)),
)
The myapp urls included in the first urlconf:
urlpatterns = patterns('',
url(r'^$', IndexView.as_view(), name="index"),
....
url(r'^reward/$', RewardsList.as_view(), name="reward_list"),
url(r'^redeem/(?P<reward_code>)/$', RedeemReward.as_view(), name="redeem_reward"),
url(r'^redeem/(?P<slug>\w+)/(?P<reward_code>\w+)/$', RedeemConfirmation.as_view(), name="reward_confirmation"),
)
And finally, my ROOT_URLCONF is set to myapp.urls. The index page works just fine.
From the limited knowledge that i have, i see that the URl pattern has "account/" and you are accessing "http://shielded-island-1440.herokuapp.com/accounts/profile/" which won't match any of the regex patterns in your URLConf.
Can you try modifying to url(r'^accounts/', include('allauth.urls')), ?
Related
i am using python 3.8 and getting error when i launch server:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/
Using the URLconf defined in djangoProject.urls, Django tried these URL patterns, in this order:
polls/
admin/
The empty path 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.
my polls/urls.py:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
my djangoProject/urls.py:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url("polls/", include('polls.urls')),
url("admin/", admin.site.urls),
]
The root urls contains two items: polls/ and admin/. This thus means that if you visit the root URL (127.0.0.1:8000/), it will not trigger any view, since no view has been "attached" to that URL pattern. You thus will have visit a page to trigger the view, or change the URL patterns to enable visiting the index view if you visit the root URL.
Option 1: visit /polls/
You can visit the page by visiting:
127.0.0.1:8000/polls/
Option 2: link index to the root URL
You can change the URL patterns to trigger index when visiting the root URL with:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
# ↓↓ empty string
url('', include('polls.urls')),
url('admin/', admin.site.urls),
]
I have tried to set up social authentication for steam login button. I have followed all these steps, and added steam necessary stuff: adding API key to settings and steam.SteamOpenId to authentication backends.
The error:
Using the URLconf defined in Test.urls, Django tried these URL patterns, in this order:
^ ^$ [name='index']
^login/(?P<backend>[^/]+)/$ [name='begin']
^complete/(?P<backend>[^/]+)/$ [name='complete']
^disconnect/(?P<backend>[^/]+)/$ [name='disconnect']
^disconnect/(?P<backend>[^/]+)/(?P<association_id>[^/]+)/$ [name='disconnect_individual']
^admin/
Hyperlink i used to make login button:
Login
urls.py file of project:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^', include('Home.urls')),
url('', include('social.apps.django_app.urls', namespace='social')),
url(r'^admin/', admin.site.urls),
]
urls.py file of application Home:
from django.conf.urls import url
from . import views
app_name = 'Home'
urlpatterns = [
url(r'^$', views.index, name='index'),
]
Full Project Here.
I am wondering if there is still something that i need to set up, do i need to add views to url patterns? If so, then which? where is social authentication urls file located?
I am trying to build a website with Django. I am new to Django and have followed the Tango with Django tutorial.
I keep getting an URlconf error I do not understand.
I have a domain (www.example.com), an app (mainApp) and two views in mainApp (homePage, registration).
I want
http://www.example.com to be matched with the homePage view
http://www.example.com/registration/ to be matched with the registration view.
My urls.py file for the project is
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('mainApp.urls')),
)
The urls.py file for mainApp is
from django.conf.urls import patterns, url
from mainApp import views
urlpatterns = patterns(
'',
url(r'^$', views.homePage, name='homePage'),
url(r'^registration/$', views.registration, name='registration'),
)
This configuration displays the homePage view correctly, but not the registration view. The error is:
Using the URLconf defined in myProject.urls, Django tried these URL
patterns, in this order:
^admin/
^$
^/
The current URL, registration/, didn't match any of these.
What causes the error?
It looks fine. If you're hosting it online you should restart the webapp, if hosting it locally then restart the local host. Without restarting it the changes don't register.
I am getting a 404 error for a few of my URLs in my django project. For example:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/admin
Using the URLconf defined in some_project.urls, Django tried these URL patterns, in this order:
^$ [name='home']
^admin/$
But I haven't changed anything to the file.
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
url(r'^$', 'views.index',name='home',),
url(r'^admin/$', include(admin.site.urls)),
)
This problem seemed to come after I installed Django Evolve. Not sure if that has something to do with it.
Your pattern is not correct, it should be:
url(r'^admin/', include(admin.site.urls)),
Your request url is http://127.0.0.1:8000/admin, but your urlpattern is url(r'^admin/$', include(admin.site.urls)).
There is an extra / in the urlpattern.
If you want to include other URLConfs, here's an example to include other URLconfs:
from django.conf.urls import include, patterns, url
urlpatterns = patterns('',
# ... snip ...
url(r'^comments/', include('django.contrib.comments.urls')),
url(r'^community/', include('django_website.aggregator.urls')),
url(r'^contact/', include('django_website.contact.urls')),
# ... snip ...
)
As Burhan correctly pointed out, you need to remove the trailing $ so that include could work.
The reason is because in regex trailing $ matches right after the last character in the string.
It was a problem with the settings file. There was a merge problem with what I had and another developer had.
The /$ wasn't related to this problem. I added it when I was trouble shooting.
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.