I have little trouble with Django. It cannot recognise urls with get params like this:
http://example.com/login/?next=/me/registrace/
I suppose it is due to bad settings, but I dont know where. The same problem is even in administration.
This is what I see on error page:
Using the URLconf defined in example.urls, Django tried these URL patterns, in this order:
^admin/
^imperavi/
^login/$ [name='login']
^$ [name='index']
The current URL, login/, didn't match any of these.
My urls.py
from django.conf.urls import patterns, include, url
from django.utils.translation import ugettext_lazy as _
from django.contrib import admin
from example.views import IndexView, LoginView
admin.autodiscover()
urlpatterns = patterns('',
url(_(r'^admin/'), include(admin.site.urls)),
url(_(r'^imperavi/'), include('imperavi.urls')),
url(_(r'^login/$'), LoginView.as_view(), name='login'),
url(_(r'^$'), IndexView.as_view(), name='index'),
)
I tried to remove ugettext translations, but it didnt help.
I also tried to remove all my rules and let there just admin, but still it doesn't work. I tried admin url:
http://example.com/admin/auth/user/?o=-1
There is a slash missing in the last url:
...
^$ [name='index']
The current URL, login/, didn't match any of these.
There is it: your rule should be url(_(r'^/$'), IndexView.as_view(), name='index'),
Related
I'm trying to access a URL, http://localhost:8000/calc, but it gives me this error:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^admin/
^$ [name='home']
^calc/
The current path, calc, didn't match any of these.
This is what I currently have for mysite URL and secondapp URL:
# mysite/urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'',include('firstapp.urls')),
url(r'^calc/',include('secondapp.urls')),
]
# secondapp/urls.py
from django.conf.urls import url
from secondapp.views import CalcPage
urlpatterns = [
url(r'calc/', CalcPage.as_view(), name='calc'),
]
As per the URL configuration you have stated in mysite.url and secondapp.url you link would be
localhost:8000/calc/calc/
which IMO would be confusing, if I am correct, URL you want is
localhost:8000/calc/
For that you have to change the url you have defined in secondapp.url to
from django.conf.urls import url
from secondapp.views import CalcPage
urlpatterns = [
url(r'$', CalcPage.as_view(), name='calc'),
]
This would make the ClacPage accessible on
localhost:8000/calc/
See / is very important when defining URLs.
use below reg-ex in urls.py
r'^calc/$'
I'm going through the polls Django tutorial and have searched for answers to this. So far:
I made sure I'm using the right directories. The main urls.py is in mysite/mysite/, the polls urls.py is in mysite/polls/urls.py.
Tried adding 'polls' to INSTALLED_APPS in the settings.py of mysite/mysite.
Am making sure that I am requesting 127.0.0.1:8000/polls and not 127.0.0.1:8000
I am using Python 3.4 and Django 1.9, same as the tutorial.
I am still receiving this message:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/polls
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^polls/
^admin/
The current URL, polls, didn't match any of these.
mysite/mysite/urls.py
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^polls/', include('polls.urls')),
url(r'^admin/', admin.site.urls),
]
mysite/polls/urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^%', views.index, name='index'),
]
mysite/polls/views.py
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world")
In your polls/urls.py
change url(r'^%', views.index, name='index') to url(r'^$', views.index, name='index').
Also in your urls.py, you have route for 127.0.0.1:8000/polls/ and you request for 127.0.0.1:8000/polls . Notice the trailing slash.
So you should request to 127.0.0.1:8000/polls/ .
Add APPEND_SLASH = True in your settings.py file so that it would redirect 127.0.0.1:8000/polls to 127.0.0.1:8000/polls/ .
So i tried your Index view with your urls.py.
It works, the only thing different is in your "Request URL, you must request for - 127.0.0.1:8000/polls/%
changing your urls to
url('^/%', index) - polls URLs.py
url('^polls', include('polls.urls')) - project URLs
This will work.
I'm trying to create a site using Django. I have the index view working, however I want to create a simple custom view and map to it but I am unable to. I'm getting a 404 error.
The app inside my project is called emails.
Here are the files:
base/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^emails/$', include('emails.urls')),
)
emails/urls.py
from django.conf.urls import patterns, include, url
from emails import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^custom/$', views.custom, name='custom'),
)
emails/views.py
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello world, you're at the index.")
def custom(request):
return HttpResponse("This is a custom view.")
Here is the 404:
Using the URLconf defined in crm.urls, Django tried these URL patterns, in this order:
^admin/
^/emails/$
The current URL, emails/custom, didn't match any of these.
When I visit localhost:8000/emails/ - I see the index view. However localhost:8000/emails/custom/ is returning a 404 error. Any help would be appreciated!
This url(r'^emails/$', include('emails.urls')), should be without the dollar sign $:
url(r'^emails/', include('emails.urls')),
You don't want to end your path after emails, so don't end the string with the regex character $. Let it be able to be continued in the other urls.py file
I'm troubleshooting an issue with my urls.py file and I just noticed that the django default 404 page is returning "No Post matches the given query." in the body rather than
"Using the URLconf defined in X, Django tried these URL patterns in this order:
^admin/
^$
...
The current URL, myurl/ didn't match any of these."
Is this a toggle somewhere? I know I've seen it before...I'm using Django 1.5.1, DEBUG = TRUE is set in settings.py and I have other URLs defined in urls.py:
from django.conf.urls import patterns, include, url
from django.contrib import admin, flatpages
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
# Uncomment the admin/doc line below to enable admin documentation:
url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^$', 'blog.views.index'),
url(r'^(?P<slug>[\w\-]+)/$', 'blog.views.post'),
url(r'^contact/$', 'contact.views.contact'), #troubleshooting this one
)
I think that this is because you get the error because you use the shortcut function get_object_or_404 with Post model.
So the urls patterns work ok. Try to locate where you use this function and add some printing or break with pdb.
What am I doing wrong ?
My URL : http://localhost:8000/login/
The DEBUG log from Django :
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/login/
Using the URLconf defined in dealers.urls, Django tried these URL patterns, in this order:
^login|home/ ^login/$
^login|home/ ^home/$
^login|home/ ^home/dealer/(?P<dealer_id>\d+)/$
^admin/
The current URL, login/, didn't match any of these.
urls.py file :
from django.conf.urls.defaults import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^login|home/',include('dealerpanel.urls')),
(r'^admin/', include(admin.site.urls))
)
dealerpanel/urls.py :
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns('dealerpanel.views',
(r'^login/$','login'),
(r'^home/$','home'),
(r'^home/dealer/(?P<dealer_id>\d+)/$','details')
)
## urls.py
urlpatterns = patterns('',
(r'',include('dealerpanel.urls')),
(r'^admin/', include(admin.site.urls))
)
Change the prefix for including dealerpanel.urls to be the empty string. I think the way you have it structured it would actually be looking for a url like:
/login/login/
/login/home/
/home/login
...
Add something like this to your dealerpanel/urls.py so that http://localhost:8000/login/ will hit the view dealerpanel.views.target_view:
urlpatterns = patterns('dealerpanel.views',
...
(r'','target_view'),
)
This means the empty string after login (or home) will match the target_view