Reputation: 448
How would you go about creating a button in your templates of an app in Django. I have a script in my views.py:
def my_python_script(request):
if request.is_ajax:
# stuff here
else:
return HttpRequest(status=400)
But how do I actually turn this into a button? Is there some html or css I need to put somewhere? I saw some things about a templates directory in the application but I'm unsure on what things to put there and in what formats.
Upvotes: 0
Views: 749
Reputation: 563
You would do like the following:
<button type='button' id="my_button">Click me</button>
And with a js (jquery):
$("#my_button").click(){
$.get("url_to_view",{data:"data",function(response){
// response to do something after the request
});
});
Upvotes: 1