我創建的Django form.py文件:如何清除在Django表單數據
from django import forms
from models import ResumeModel
class ResumeForm(forms.ModelForm):
username = forms.CharField(max_length = 200)
first_name = forms.CharField(max_length = 200)
last_name = forms.CharField(max_length = 200)
fathers_name = forms.CharField(max_length = 200)
email = forms.EmailField(required=True, label='Your e-mail address')
message = forms.CharField(widget=forms.Textarea)
class Meta():
model = ResumeModel
fields =('username','first_name','last_name','fathers_name','email','message')
views.py:
def save(request):
if 'submit' in request.POST:
form = ResumeForm(request.POST)
if form.is_valid():
form.save()
form = ResumeForm()
return render(request, '/success/', {'form': form})
else:
form = ResumeForm()
args = {}
args.update(csrf(request))
args['form'] =form
return render_to_response('create.html',args)
urls.py:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^save/', 'Resume.views.save'),
url(r'^success/$', TemplateView.as_view(template_name='success.html')),
)
現在一切正常。問題是,當我提交表單時,它會轉到成功頁面,當我回到上一頁是/ save/page時,它將保存我提交的字段中的所有值。如何清除字段,如果我按back button to go back to that form page having url as "/save/ "
在哪裏編寫這些行> –
無論你想要什麼。來自w3schools 的示例 [link](http://www.w3schools.com/jquerymobile/tryit.asp?filename=tryjqmob_event_pageshow)。 – obayhan