Please explain! How to make a link to a django request. For example:

поле1 поле2 поле3 

We click on the field1, the variable field1 is taken, it is sent to the request to the database, and we display the result in a new html page.

Just do not kick for a stupid question, far away. )

    2 answers 2

    We make as a normal link:

     <a href="first_link/">поле1</a> 

    In urls.py we register:

     from django.views.generic.simple import direct_to_template urlpatterns = patterns('', url(r'^first_link/$', direct_to_template, {'template': 'first.html'}) ) 

    UPD: If the query is to the database, then instead of direct_to_template , specify the required view, and render the necessary html from it.

    UPD2: It was also written about this: here

    • The request to the database turns out to be fine, but how to pass the variable to view def hisping (request): h = SSwAlive.objects.filter (is_deleted = 1, sw = '???') return render_to_response ('swhistory.html', {'h ': h}) - avdoshkin
    • As I understand it, this is a continuation of the question? Then please specify what you have failed. In the commentary you pass the variable h to the page - everything is correct ... - Kozlov Sergei
    • Yes, I pass the h variable to the page, but to execute the query, you need to take a variable with field1 and insert it into h = SSwAlive.objects.filter (is_deleted = 1, sw = 'field1') return render_to_response ('swhistory.html', {' h ': h}) It turns out a new page. - avdoshkin
    • Well, it became clear, otherwise it was not obvious before) Actually, this is all written on the link that I added to my post I will write here, in detail. We make a parcel from the form by the method post (for clarity) <form action = "first_link /" method = "post"> {% csrf_token%} ]] "/> <input type =" submit "name =" submit "value =" Field1 "> </ form> view: h = SSwAlive.objects.filter(is_deleted=1,sw=request.POST['sw']) return render_to_response('swhistory.html',{'h':h}) And read the documentation, there it is all perfectly described! - Kozlov Sergei

    I answer your question.

    it was necessary in urls.py to transfer the second variable in views.py

      urls.py url(r'^switch/(\S+)/$', 'swhist'), 

    and in views.py, handle it and return in test.html

      def test(request, vars): res = SSwAlive.objects.filter(is_deleted=1, sw='%s' %vars) return render_to_response('test.html',{'res':res})