Arjun Kashyap
Arjun Kashyap

Reputation: 663

Why M I getting a 404 in my django project?

So I have a page which I want to render after the details section in my project. My urls.py is below:

    from django.conf.urls import url
from . import views

app_name = 'main'

urlpatterns = [
    url(r'^home/', views.home, name='home'),    # Home page
    url(r'incubators/$', views.incubators, name='incubators'),    # Incubator list page
    url(r'about/', views.about, name='about'),          # Websie about page
    url(r'results', views.result, name = 'result'),         # For search function
    url(r'incubators/(?P<incubator_id>[0-9]+)/', views.details, name = 'details'),      # shows details of incubators
    url(r'incubators/add-incuabtor/$', views.AddIncubator.as_view(), name = 'add-incubator'),     # Adding Inc
    url(r'/add-details/', views.AddDetails.as_view(), name = 'add-details'), #for additional details
    url(r'news/', views.news, name = 'news'),
    url(r'added/', views.added, name = 'added'),      #your incubator will be added soon page
    url(r'apply/', views.apply, name = 'apply'),
    url(r'done/', views.done, name = 'done'),
    url(r'location/', views.location, name = 'location'),
    url(r'prediction/', views.prediction, name = 'prediction'),
    url(r'^/locate/', views.locate, name = 'locate'),
]

I want to open a page (present in the details.html) which will be showing some info (in my case latitude and longitude) of that particular element. Following is my views.py

def details(request, incubator_id):
    inc = get_object_or_404(Incubators, pk = incubator_id)
    details = Details.objects.get(pk = incubator_id)
    return render(request, 'main/details.html', {'inc': inc, 'details': details})

def locate(request):
    locate = get_object_or_404(Incubators, pk = incubator_id)
    return render(request, 'main/locate.html', {'locate': locate})

But I am getting the following error:

NameError at //locate/

name 'incubator_id' is not defined

Request Method:     GET
Request URL:    http://127.0.0.1:8000//locate/
Django Version:     1.11.3
Exception Type:     NameError
Exception Value:    

name 'incubator_id' is not defined

Exception Location:     C:\Users\my dell\Desktop\Project\junityme\main\views.py in locate, line 137
Python Executable:  C:\Users\my dell\AppData\Local\Programs\Python\Python36-32\python.exe

Using the URLconf defined in Ekyam.urls, Django tried these URL patterns, in this order:

I think I am doing some mistake in making urls for this. Help would be appriciated.

Upvotes: 0

Views: 37

Answers (1)

Arya
Arya

Reputation: 1469

http://127.0.0.1:8000//locate/ would be looking for a URL pattern that starts with "locate," but you don't have any URL patterns that start with locate. The URL should match the pattern, not the name you give it, or the view name.

Upvotes: 2

Related Questions