When a link is clicked ( Which is generated from a search result ) , it should take the name/primary key of that particular data to a view . I have read through the documentation of URL dispatcher , but haven’t got a concrete idea of how to pass the primary key of a certain row of a table to another view .
Any help is much appreciated .
Till now I have done this .
def that_view ( request , num)
---view code
search is generating a particular Url . When I click on that , the primary key should pass to this that_view to be processed to view the data .
Is this the right way to do it , if yes how exactly should I modify my urls.py and also the template that generates the data search (i.e the url) .
You might ask me to read the documentation , again and again . But I did . No help . Any code snippet of any kind ( even a link to such, and not a link to the documentation ) would help .
This is my views .
def map_search(request):
lcount = Open_Layers.objects.all()
form = SearchForm()
if request.method == 'POST':
form = SearchForm(request.POST)
if form.is_valid():
data = form.cleaned_data
val=form.cleaned_data['LayerName']
a=OsmLayers()
b=Open_Layers()
c=Sdr_Layer()
data = []
data1=[]
data2=[]
data3=[]
data1 = OsmLayers.objects.filter(Layername__icontains=val)
data2 = Open_Layers.objects.filter(Layer_name__icontains=val)
data3 = Sdr_Layer.objects.filter(layer_name__icontains=val)
data.append(data1)
data.append(data2)
data.append(data3)
return render_to_response('searchresult.html', {'data':data})
else:
form = SearchForm()
else:
return render_to_response('mapsearch.html', {'form':form})
you just need to pass your “num” via the url.
in your urls.py:
then inside your view, you can use the num variable as long as you want
check out https://docs.djangoproject.com/en/dev/topics/http/urls/ for more info on urls formatting and regular expressions