Reputation: 323
as a beginner in Django, I have a problem with producing the correct link to the edit form.
If you manually type in the address
localhost:8000/edit/1
from your browser i receive a form for editing.
views.py
def edit(request, stat_id):
stat = fms.objects.get(pk=stat_id)
if request.method == 'POST':
form = fmsForm(request.POST, instance=stat)
if form.is_valid():
form.save()
return HttpResponseRedirect('/fmstat/')
else:
form = fmsForm(instance=stat)
return render(request, 'fmstat/edit.html', {'form': form,})
url.py
url(r'^edit/(?P<stat_id>(\d+))', 'fmstat.views.edit'),
link in template:
<a href="{% url fmstat.views.edit %}">link</a>
Upvotes: 0
Views: 219
Reputation: 39659
You are not passing the stat_id
{% url fmstat.views.edit stat_id=some_id %}
Also its a good approach to use the url name in url tag:
url(r'^edit/(?P<stat_id>(\d+))',
'fmstat.views.edit', {},
name='stat_edit'),
then:
{% url stat_edit stat_id=some_id %}
Upvotes: 1