python - Django do not render ModelForm -
i working on little project on django, have had issues on rendering modelform. in main.html tag {{form.ad_p}} doesn't seem working. see "save" button , don't see modelform fields.
if put below code shell
form = addpath() form.as_p()
i see:
form.as_p() u'<p><label for="id_name">name:</label> <input id="id_name" maxlength="200" name="name" type="text" /></p>\n<p><label for="id_route_data">route data:</label> <textarea cols="40" id="id_route_data" name="route_data" rows="10">\r\n</textarea></p>'
can explain, doing wrong?
i searched on stackoverflow, same problem hasn't been resolved. hope, i'll more lucky
models.py:
from django.db import models django.contrib.auth.models import user class path(models.model): user = models.foreignkey(user) name = models.charfield(max_length='200') route_data = models.textfield() def __unicode__(self): return self.name
views.py:
from django.shortcuts import render_to_response django.http import httpresponse django.core.context_processors import csrf google_maps.forms import addpath def index(request): args = {} args.update(csrf(request)) form = addpath() return render_to_response('main.html', args) def add_path(request): #me = request.user me = 'test' if request.method == 'post': form = addpath(request.post) if form.is_valid(): tmpform = form.save(commit=false) tmpform.user = me tmpform.save() return httpresponse('saved') else: return httpresponse(form.errors)
main.html
{% extends 'basis.html' %} {% block leftbar %} <form action={% url 'add_path' %} method="post"> {% csrf_token %} {{ form.as_p }} <input type="hidden", id="coordinate" name="coordinate"/> <input type="submit" name="submit" value="save"/> </form> {% endblock %}
Comments
Post a Comment