I’m trying to make a view in Django, in where if the edit button is pressed on that page it is passed on to another view as a session.
JavaScript
x
18
18
1
def page(request,user_input):
2
entry = util.get_entry(user_input)
3
name = user_input.capitalize()
4
request.session['name'] = name
5
request.session['entry'] = entry
6
7
8
if request.GET.get("edit"): # **<- This is not working for some reason.**
9
request.session['edit'] = True
10
else:
11
request.session['edit'] = False
12
13
14
return render(request, "homepage/page.html", {
15
"entry":entry,
16
"title":name,
17
})
18
Here is my page.html file
JavaScript
1
17
17
1
{% block body %}
2
3
{% if entry %}
4
5
<h1>{{title}}</h1>
6
7
{{ entry }}
8
9
10
{% endif %}
11
12
<form action="{% url 'create' %}" name='edit'>
13
<input type="submit" value='edit' class="button">
14
</form>
15
16
{% endblock %}
17
This is the view where I want to use the session
JavaScript
1
8
1
def create(request):
2
change =request.session['edit']
3
if request.GET.get('submit'):
4
title = str(title).lower()
5
if change:
6
util.save_entry(title,content)
7
return HttpResponseRedirect('/index')
8
Advertisement
Answer
You can specify a key-value pair by making use of the <button>
tag, so then the form should look like:
JavaScript
1
3
1
<form action="{% url 'create' %}">
2
<button name="submit" value="edit" type="submit" class="button">edit</button>
3
</form>