Django 404: Page not found (404) - URLConf not matching - python

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).

Related

I'm following the Django documentation 01 but it can't work for me

I'm a beginner at Django.
views.py/my_app
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello World")
urls.py/my_app
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
]
urls.py/my_project
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('product/', include('product.urls')),
path('admin/', admin.site.urls),
]
Error:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/product
Using the URLconf defined in Zero.urls, Django tried these URL patterns, in this order:
admin/
The current path, product, 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.

page not found when making new url / view Django

Hello i am trying to add a basic url called localhost:8000/shop
so that when i am on my homepage, I can click a link called shop and It will lead me to localhost:8000/shop
in my urls.py i added
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import include, path
from homepage import views
urlpatterns = [
path('' , views.home),
path('admin/', admin.site.urls),
path('reviews/' , include('reviews.urls')),
path('shop/' , include('product.urls')),
]
in my folder called product i have a urls.py file with
from django.urls import include, path
from . import views
urlpatterns = [
path('shop/' , views.shop),
]
and in my product folder i have a views.py file with
from django.shortcuts import render
# Create your views here.
def shop(request):
return render(request, 'product/shop.html')
linking It to my html file inside my product folder..
when i run the server, I get this error message
Page not found (404)
Request Method: GET
Request URL: http://localhost:8000/shop
Using the URLconf defined in yorleico.urls, Django tried these URL patterns, in this order:
admin/
reviews/
shop/
The current path, shop, didn't match any of these.
What am i doing wrong?!
To register the path /shop, you need to use path('' , views.shop), in the urls.py in your shop app. The /shop prefix is already being defined by the path('shop/' , include('product.urls')), line in your project level urls.py.
All url patterns in the product app already start with shop/, due to the path('shop/', include('product.urls')). Therefore your urls.py for the products app should look like:
# product/urls.py
from django.urls import include, path
from . import views
urlpatterns = [
path('' , views.shop),
]
otherwise the path should be /shop/shop/.

Path cannot be found in django

I am working on a django project. The project includes 2 apps namely jobs and blog. The url.py of the main project file is:
from django.contrib import admin
from django.urls import path,include
from django.conf import settings
from django.conf.urls.static import static
import jobs.views
urlpatterns = [
path('admin/', admin.site.urls),
path('', jobs.views.home, name= 'home'),
path('blog/', include('blog.urls'))
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
You can understand that I am calling the output of the jobs in the home. The url.py of the blog is:
from django.urls import path
from . import views
urlpatterns = [
path('', views.allblogs, name= 'allblogs'),
]
and the views.py of the blog is:
from django.shortcuts import render
def allblogs(request):
return render(request, 'blog/allblogs.html')
This gives an error that the blog/ can not be found. I must mention I make a allblogs.html in the address project/blog/templates/blog The webpage shows that it tries to find the page in this ditrectory: ...project\jobs\templates\blog\allblogs.html
The error message is:
TemplateDoesNotExist at /blog/
Request URL: http://localhost:8000/blog/
Exception Type: TemplateDoesNotExist
I dont know why it is trying to find it in jobs where it should search for it in blogs folder.
Can someone help? May be I have done something silly..

Django new URL not working

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/$'

Django url Routing Error

I have a very basic url router in my django project:
from django.conf.urls import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.contrib import admin
admin.autodiscover()
urlpatterns = staticfiles_urlpatterns()
urlpatterns += patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^/?', include('customApp.urls')),
)
When I start the dev server and go to 127.0.0.1:8000/admin/, I get a ViewDoesNotExist at /admin/ error.
Here is the content of the exception:
Could not import customApp.views.event. View does not exist in module customApp.views.
I've already tried re-ordering the urls (I have no idea how that would help, but I tried it anyway) and changing r'^/?' to r'^/'.
When I comment out the last url, the admin page works again.
Here's the customApp.urls code:
from django.conf.urls import patterns, include, url
import django.contrib.auth.views
import django.contrib.auth
urlpatterns = patterns('customApp.views',
url(r'^$', 'index'),
url(r'^rest/v1/event/add/$', 'event'),
url(r'^rest/v1/reports/$', 'reports'),
)
urlpatterns += patterns('',
url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'}),
)
It is simple buddy. Django cannot find customApp views. Please ensure whatever views you have got in urls.py, it should exist.
Thanks

Categories