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/$'
Related
So, everything in my newly started Django project is working fine except this logout url. I'm using django=1.11.17 and python 3. When I try to logout from the accounts, this is the error I get.
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/%25%20url%20'accounts:logout'%20%25
Using the URLconf defined in conspiverse_project.urls, Django tried these URL patterns, in this order:
^$ [name='home']
^test/$ [name='test']
^thanks/$ [name='thanks']
^admin/
^accounts/
^accounts/
The current path, % url 'accounts:logout' %, 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.
accounts/urls.py
from django.conf.urls import url, include
from django.contrib.auth import views as auth_views
from . import views
app_name = 'accounts'
urlpatterns = [
url(r"login/$", auth_views.LoginView.as_view(template_name="accounts/login.html"),name='login'),
url(r"logout/$", auth_views.LogoutView.as_view(template_name="thanks.html"), name="logout"),
url(r"signup/$", views.SignUp.as_view(), name="signup"),
]
project/urls.py
from django.conf.urls import url, include
from django.contrib import admin
from . import views
urlpatterns = [
url(r"^$", views.HomePage.as_view(), name="home"),
url(r"^test/$", views.TestPage.as_view(), name="test"),
url(r"^thanks/$", views.ThanksPage.as_view(), name="thanks"),
url(r"^admin/", admin.site.urls),
url(r"^accounts/", include("accounts.urls", namespace="accounts")),
url(r"^accounts/", include("django.contrib.auth.urls")),
]
settings.py
STATIC_URL = '/static/'
STATICFILES_DIR = [os.path.join(BASE_DIR,'static')]
LOGIN_REDIRECT_URL = 'test'
LOGOUT_REDIRECT_URL = 'thanks'
I tried verifying the URL paths, cross-checked almost everything, it is driving me crazy. Huge thanks for the help!
I have the following urls.py file in a Django project, and I am getting an error which I assume is relating to the latest syntax relating to urls and paths.
The code I have in the urls file which is url.py in the mysite (outermost directory) is:
from django.urls import path
from django.conf.urls import url, include
urlpatterns = [
path(r'^$', include('aboutme.urls')),
]
The error message is:
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^$
The empty path didn't match any of these.
In the actual app (website folder) which is called 'aboutme', the urls.py file looks like this:
from django.urls import path
from django.conf.urls import url, include
from .import views #this is the main thing we are going to be doing ....returning views!
urlpatterns = [
path(r'^$', views.index,name='index'),
]
Can anyone shed any light on the correct syntax or what I am doing wrong?
UPDATE:
I also went back and tried to update the main mysite's url.py file to include the admin commands (which were in the previously working version). The code and resultant error are also shown below:
Tried this code:
from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
urlpatterns = [
path('admin/', admin.site.urls),
path(r' ', include('aboutme.urls')),
]
Error
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
admin/
The empty path didn't match any of these.
Remove the ^ and $ in the urls.py files.
from django.urls import path
from django.conf.urls import url, include
urlpatterns = [
path(r'', include('aboutme.urls')),
]
And in your app urls.py:
from django.urls import path
from django.conf.urls import url, include
from .import views #this is the main thing we are going to be doing
app_name="myappname"
urlpatterns = [
path(r'', views.index,name='index'),
]
In django 2.0 they are not needed anymore if you are using path().
Related link: https://code.djangoproject.com/ticket/28691
I'm new to Django, and my first major project of sorts is to go through an existing Django Web App to update it, streamline it and optimize it in any way that I can. I'm having some difficulty in getting it to run on my machine, however.
When navigating to the local development server at localhost:8000/ I get the following error:
Using the URLconf defined in core.urls, Django tried these URL patterns, in this order:
^home/$ [name='portal']
^agentexoplanet/admin/
^agentexoplanet/agentex/ [name='agentex_redirect']
^agentexoplanet/admin/agentex/event/(?P<planetid>\d+)/calibrators/(?P<calid>\d+)/$ [name='agentex_admin_calib']
^agentexoplanet/admin/agentex/event/(?P<planetid>\d+)/calibrators/$ [name='agentex_all_calib']
^agentexoplanet/admin/
^agentexoplanet/
^static/(?P<path>.*)$
The current URL, , didn't match any of these.
This is the core.urls file:
from django.conf import settings
from django.conf.urls import include, url
from django.contrib import admin
from django.contrib.staticfiles import views
from django.views.generic import RedirectView
from django.contrib.auth.views import login, logout
from agentex import urls
from agentex.views import home
from agentex.admin import calibrator_check, allcalibrators_check
#from admin.site import urls
#from showmestars.views import newimage, latestimages
admin.autodiscover()
urlpatterns = [
#(r'^api/', include('odin.api.urls')),
url(r'^home/$', home, name='portal'),
url(r'^agentexoplanet/admin/', include(admin.site.urls), name='agentexo_admin'),
url(r'^agentexoplanet/agentex/', RedirectView.as_view(url='/agentexoplanet/'), name='agentex_redirect'),
url(r'^agentexoplanet/admin/agentex/event/(?P<planetid>\d+)/calibrators/(?P<calid>\d+)/$',calibrator_check, name='agentex_admin_calib'),
url(r'^agentexoplanet/admin/agentex/event/(?P<planetid>\d+)/calibrators/$',allcalibrators_check, name='agentex_all_calib'),
url(r'^agentexoplanet/admin/', include(admin.site.urls), name=''), # QUERY
url(r'^agentexoplanet/',include(admin.site.urls), name='agentexo_urls'),
#url(r'^showmestars/newimage/$', newimage, {'eventid':0}, name='showmestars_newimage'),
#url(r'^showmestars/(?P<eventid>\w+)/$', latestimages, name='showmestars_latestimage'),
#url(r'^showmestars/$', latestimages, {'eventid':0}, name='showmestars_latestimage_event'),
#url(r'^login/$',login, name='site_login'),
#url(r'^logout/$',logout, name='site_logout'),
]
if settings.DEBUG:
urlpatterns += [
url(r'^static/(?P<path>.*)$', views.serve),
]
And my project (agentex) urls file:
from django.conf.urls import include, url
from django.contrib.auth.views import login, logout
from .views import *
from django.conf import settings
urlpatterns = [
url(r'^$',index, name='index'),
url(r'^account/login/$', login, {'template_name' :'login.html'}, name='login'),
url(r'^account/logout/$', logout,{'template_name' :'logout.html'}, name='logout'),
url(r'^account/register/$', register, name='register'),
url(r'^account/$', editaccount, name='editaccount'),
url(r'^profile/$',profile, name='profile'),
url(r'^planets/$',target, name='target'),
url(r'^fitsanalyse',fitsanalyse, name='fitsanalyse'),
url(r'^test',tester, name='tester'),
url(r'^briefing/read/$',read_manual_check, name='read_manual_check'),
url(r'^briefing/$',briefing, name='briefing'),
url(r'^comment/$',addcomment, name='addcomment'),
url(r'^(?P<code>\w+)/view/$',addvalue, name='addvalue'),
url(r'^(?P<code>\w+)/graph/update/$',updatedataset, name='updatedataset'),
url(r'^(?P<code>\w+)/lightcurve/advanced/$',graphview, {'mode' : 'advanced','calid':None}, name='advanced-graph'),
url(r'^(?P<code>\w+)/lightcurve/me/$',graphview, {'mode' : 'simple','calid':None}, name='my-graph'),
url(r'^(?P<code>\w+)/lightcurve/calibrator/update/$',classifyupdate, name='classifyupdate'),
url(r'^(?P<code>\w+)/lightcurve/calibrator/$',graphview, {'mode' : 'ave','calid':None}, name='average-graph'),
url(r'^(?P<code>\w+)/lightcurve/calibrator/(?P<calid>\w+)/$',graphview, {'mode' : 'ave'}, name='calibrator-graph'),
url(r'^(?P<code>\w+)/lightcurve/$',graphsuper,name='super-graph'),
url(r'^(?P<code>\w+)/$',infoview, name='infoview'),
url(r'^(?P<code>\w+)/data.(?P<format>\w+)',measurementsummary, name='measurementsummary'),
]
I'm not entirely sure of the error here. My core.urls file links to index.html, but I imagine it isn't linking correctly. Does anybody have any ideas?
Thanks in advance (and apologies for not posting an image - StackOverflow wouldn't let me).
Currently getting a 404 error for my application when I try to access the url /contato, and I am not sure why, can anyone help me?
Here is the error:
Page not found (404)
Request Method: GET
Request URL: http://localhost:8002/contato
(...)
^contato/
(...)
Here is my code.
My main urls.py has:
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.contrib import admin
urlpatterns = patterns('',
url(r'^admin/password_reset/$', 'django.contrib.auth.views.password_reset', name='admin_password_reset'),
url(r'^admin/password_reset/done/$', 'django.contrib.auth.views.password_reset_done'),
url(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$', 'django.contrib.auth.views.password_reset_confirm'),
url(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
url(r'^admin/', include(admin.site.urls)),
url(r'^perfil/', include('perfil.urls')),
url(r'^contato/', include('contato.urls')),
url(r'^$', 'views.index', name='index'),)
My contato.urls.py:
from django.conf.urls.defaults import patterns, url
urlpatterns = patterns('contato.views',
url(r'^contato/$', 'contato', name="contato"),
)
my views.py in contato:
from django.shortcuts import render_to_response
from django.template import RequestContext
def contato(request):
render_to_response('contato/contato.html',locals(),context_instance=RequestContext(request),)
You don't have a match for the url "/contato". In your base urls.py, you point the prefix "/contato" to include contato.urls, and then in that file you have a single URL which is again "/contato": so the combined URL for that view is "/contato/contato".
If you just want the URL to match "contato", you should either get the included url to match just "^$", or (probably better) don't bother including the separate urls.py and match the view directly from the base file.
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