title: How do I access form fields in a template in Django?
body: <p>I am using a model-based form to create a form based off a data model. The insert part works fine, but I am now trying to do the "edit" page. my problem is I need the ID/primary key of the original model for the post action and documentation (and a previous thread here) seems to have told me to try both form.id and form.instance.id, but neither seem to work. Any ideas or help is appreciated!</p>
  
  <p>Here's my template:</p>
  
  <pre><code>&lt;form action="/athlete/edit/{{ form.mod_athlete.id }}" method="post"&gt;{% csrf_token %}
  {{ form.as_p }}
  &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here's part of my View:</p>
  
  <pre><code>def changeathlete(request, athlete_id):
          if request.method == 'POST': # If the form has been submitted...
                  form = AthleteForm(request.POST) # A form bound to the POST data
                  if form.is_valid(): # All validation rules pass
                          form.save()
                          return HttpResponse("Athlete changed!") # Redirect after POST
          else:
                  mod_athlete = Athlete.objects.get(pk=athlete_id)
                  form = AthleteForm(instance=mod_athlete) # An unbound form
  
          return render_to_response('edit.html', {
                  'form': form,
          }, context_instance=RequestContext(request))
  </code></pre>
  
  <p>Any help is appreciated and if you need more info, I'll be happy to provide it. I, of course, am new to Django and real programming so I'm just building off the tutorial and this to learn. Thanks!</p>
  
  <p><strong>Update</strong></p>
  
  <p>relevant parts of urls.py: </p>
  
  <pre><code>url(r'^$', 'rosters.views.index', name='index'),
  url(r'^admin/', include(admin.site.urls)),
  url(r'^athlete/add/', 'rosters.views.createathlete'),
  url(r'^athlete/edit/(?P&lt;athlete_id&gt;\d+)/', 'rosters.views.changeathlete'),
  url(r'^meet/(?P&lt;meet_slug&gt;\w+)/', 'rosters.views.meetindex'),
  url(r'^meet/(?P&lt;meet_slug&gt;\w+)/(?P&lt;occurence_name&gt;\w+)/', 'rosters.views.occurenceindex'),
  url(r'^meet/(?P&lt;meet_slug&gt;\w+)/(?P&lt;occurence_name&gt;\w+)/events/', 'rosters.views.meetevents'),
  url(r'^meet/(?P&lt;meet_slug&gt;\w+)/(?P&lt;occurence_name&gt;\w+)/events/(?P&lt;event_id&gt;\w+)/', 'rosters.views.addathletes'),
  </code></pre>