开发者

In django , how to make a link out of a search value returned?

开发者 https://www.devze.com 2023-03-15 01:17 出处:网络
This is the inital question and I had asked , as there were 2 questions in it , I thought I will make another question from it .

This is the inital question and I had asked , as there were 2 questions in it , I thought I will make another question from it .

How to make this django attribute name search better? .

The second question there was , once a search value is returned to searchresult.html . How do I make link out of it , that would link directly to the search data .

if the result returned is "Park" , which is a name of the file , How do I make it link , which I can link to another view that shows the contents of the开发者_C百科 data ?


I read your first question. I will give you an idea.

  1. In your search results template, you have a dictionary named data. With that, you can get the ID of the object in the search results. Create a hyperlink with that ID. ex:

    <a href='/view-details/{{ data.id }}'>{{ data }}</a>
    
  2. Make a function in your views that gets the detail of an Object using it's ID. (It's parameter should require an ID.)

  3. Create a template for that view.

  4. Map the function and the url in the urls.py of your app. For example:

    url(r'^view-details/(?P)/$', 'view_details', name='details'),

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号