Poka Yoke
Poka Yoke

Reputation: 403

Django redirect to a page on click

you'll probably know that I'm a newbie in django from my question.

I want to have an html file and a python script, such that whenever the user clicks on an image on the website it redirects to the html page and runs the python script.

I am really lost in the python script that handles urls, module definitions, views, ..etc.

How can I do this?

Upvotes: 2

Views: 11526

Answers (1)

Abhishek
Abhishek

Reputation: 3068

in your template:

<a href="/myapp/mylink">
    <img src="..."/>
</a>

in your urls.py, add a new url:

url(r'^mylink/$', views.mylinkview, name='mylink'),

add a new view:

def mylinkview(request):

    # ... your python code/script
    return HttpResponseRedirect('## your redirect template url ##')  

Upvotes: 5

Related Questions