django tags and html buttons
In my base.html
I have:
blabla
{% ifequal alterprofile no %}
{% include 'registration/submittedprofile.html' %}
{% else %}
{% include 'registration/submittedprofile2.html' %}
{% endifnotequal %}
blabla
In views.py
I have alterprofile = "no"
.
How do i change alterprofile
to "yes"
. This is my submittedprofile
:
<form action="" method="get">
blablabla
<input type="submit" value="Make Changes">开发者_开发问答;
</form>
And this is my views.py
:
def userprofile(request):
alterprofile = "no"
username = request.user
return render_to_response('registration/userprofile.html', {'user': username, 'alterprofile' = alterprofile})
Is there anyone who can code the answers for me. I've tried playing round with the previous answers but to no affect.
Django variables are rendered from the server side, so you can not change the variable after it was passed to your template. What you want to achieve is done via frontend scripting.
In this case you would pass both variables to the django template, save them in your Javascript and then switch them once you clicked the button you mentioned (via onClick event handling).
You can use url arguments like:
/myurl/
/myurl/?show2
then, in your views.py you can use request.POST['show2'] to check if exists and then send a variable again to the view to be checked with your {if}s
As an aside note, either you don't understand basic request flow with web applications or you are not explaining properly what you mean with "html button", so you are not fluent with html language. Sorry if my intuition is harsh or wrong.
its not that clear what you are asking but here is how to make the logic work as I think you want it based on yoru submitted code:
in your template change it to
ifequal alterprofile "no"
to include registration/submittedprofile.html
.
When you change the view to alterprofile = "yes"
the registration/submittedprofile2.html
will be included instead if you keep your current template logic.
This is because in your view, alterprofile is assigned a string therefore its always a string. When you tried to test against no
instead of "no"
django was looking for a variable called no which doesn't exist.
This means that everytime you run it would have always included registration/submittedprofile2.html
精彩评论