बनाता है मैं फॉर्म को संपादित कर रहा हूं, यह डेटा को सही ढंग से लोड करता है जब मैं सहेजता हूं तो यह डेटाबेस में नई प्रविष्टि बनाता है।Django में प्रपत्र को संपादित करने से नया उदाहरण
यहाँ दृश्य कार्यों
def create_account(request):
if request.method == 'POST': # If the form has been submitted...
form = AccountForm(request.POST, request.FILES) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
form.save()
return HttpResponseRedirect('/thanks/') # Redirect after POST
else:
form = AccountForm() # An unbound form
return render_to_response('account_form.html', {
'form': form,
})
है -
def edit_account(request, acc_id):
f = Account.objects.get(pk=acc_id)
if request.method == 'POST': # If the form has been submitted...
form = AccountForm(request.POST, request.FILES) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
form.save()
return HttpResponseRedirect('/thanks/') # Redirect after POST
else:
form = AccountForm(instance=f) # An unbound form
return render_to_response('account_form.html', {
'form': form,
})
मैं सच में संपादन के अलग-अलग समारोह है और हटाने के लिए अलग करने के लिए की जरूरत है। मैं एक समारोह
टेम्पलेट
<form action="/account/" method="post" enctype="multipart/form-data" >
{% csrf_token %}
{% for field in form %}
<div class="fieldWrapper">
{{ field.errors }}
{{ field.label_tag }}: {{ field }}
</div>
{% endfor %}
<p><input type="submit" value="Send message" /></p>
</form>
क्या आपका मतलब है कि मुझे बचाने से भिन्न कार्य का उपयोग करना चाहिए ?? – user2134226
कृपया एसएलॉट की टिप्पणी को अनदेखा करें, यह सटीक नहीं है। –