Django Views---can't see the URL correctly -
inside app called batches, have set different url patterns. have 3 urls batches, individuals , business names. seems when goind last 2 seeying info batches time. inside app-batches have 3 tables/classes.
please see url pattern of website:
urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^batches/', include('batches.urls')), url(r'^screenings/', include('screenings.urls')), url(r'^individuals/', include('batches.urls')), url(r'^businessnames', include('batches.urls')), ]
this have in viewes:
from __future__ import unicode_literals .models import businessname .models import individuals .models import batches django.shortcuts import render django.http import httpresponse # create views here. def index(request): all_batches = batches.objects.all() html = '' batch in all_batches: url = '/batches/' + str(batch.id) + '/' html += '<a href="#"' + url + '">' + str(batch.filename)+ '</a><br>' return httpresponse(html) def detail(request, batches_id): #parametrul asta batches_id tr sa se gaseasca in urls.py din app return httpresponse("<h2>details batches id:" + str(batches_id) + "</h2") def index_businessname(request): all_businessnames = businessname.objects.all() html1 = '' bn in all_businessnames: url = '/businessnames/' + str(bn.id) + '/' html1 += '<a href="#"' + url + '">' + bn.fullname + '</a><br>' return httpresponse(html1) def detail_businessname(request, businessname_id): return httpresponse("<h2>details business names id:" + str(businessname_id) + "</h2") def index_individual(request): all_individuals = individuals.objects.all() html2 = '' in all_individuals: url = '/individuals/' + i.id + '/' html2 += '<a href="#"' + url + '">' + i.fullname + '</a><br>' return httpresponse(html2) def detail_individual(request, individuals_id): return httpresponse("<h2>details individual names id:" + str(individuals_id)+ "</h2")
this have in app urls:
urlpatterns = [ # /batches/ url(r'^$', views.index, name='index'), # /batches/2 url(r'^(?p<batches_id>[0-9]+)/$',views.detail, name="detail"), # businessname/1 url(r'^$',views.index_businessname, name="index_businessname"), # businessname/1 url(r'^(?p<businessname_id>[0-9]+)/$', views.detail_businessname, name="detail_businessname"), # individuals/1 url(r'^$', views.index_individual, name="index_individuals"), # individuals/1 url(r'^(?p<individuals_id>[0-9]+)/$', views.detail_individual, name="detail_individual"), ]
if me, owe lot. read documentation, stuck in it.
thank you, cohen
the problem defining 3 end points same urls. django searches pattern top bottom , return matches first. so, doesn't know of them specified unless explicitly tell it. so, it'd better define prefixes end points of urls in app, in same app itself.
you may define endpoints in main urls.py
,
url(r'^batches/', include('batches.urls')),
then, in app.urls.py
change them accordingly,
urlpatterns = [ url(r'^$', views.index, name='index'), url(r'^/(?p<batches_id>[0-9]+)/$',views.detail, name="detail"), url(r'^businessname/$',views.index_businessname, name="index_businessname"), url(r'^businessname/(?p<businessname_id>[0-9]+)/$', views.detail_businessname, name="detail_businessname"), url(r'^individuals/$', views.index_individual, name="index_individuals"), url(r'^individuals/(?p<individuals_id>[0-9]+)/$', views.detail_individual, name="detail_individual"), ]
Comments
Post a Comment