के साथ WTForms 'populate_obj() विधि का उपयोग करना मेरे पास एक टेम्पलेट है जो उपयोगकर्ता को उनकी उपयोगकर्ता जानकारी संपादित करने की अनुमति देता है।फ्लास्क माइक्रो फ्रेमवर्क
<form method="post">
<table>
<tr>
<td>Username:</td>
<td>{{user['username']}}</td>
</tr>
<tr>
<td>New Password:</td>
<td> <input type="password" name="password"></td>
<td>{% if form.password.errors %} {{form.password.errors}} {% endif %}<td>
</tr>
<tr>
<td>Re-enter Password:</td>
<td> <input type="password" name="confirm_password">
</td>
</tr>
<input type='hidden' name='username' value="{{user['username']}}">
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
मेरे पास उपयोगकर्ता द्वारा इस तरह के संपादन को संभालने के लिए एक दृश्य कार्य भी है। डेटाबेस जो मैं वर्तमान में उपयोग कर रहा हूं MongoDBMongoKit मॉड्यूल के साथ है। मैं अभी तक दृश्य समारोह में अभी तक ऐसा करने में सक्षम हूं, फिर भी कोई भाग्य नहीं।
def edit():
username = request.args.get('user')
user = User.find_one({'username':username}) # Is this a correct way of doing it?
form = UserForm(**what should be placed here?**, obj=user)
if request.method == 'POST' and form.validate():
form.populate_obj(user)
user.save()
return 'updated'
return render_template('edituser.html', form=form, user=user)
मैं इस उद्देश्य के लिए populate_obj(obj) पर जा रहा हूं। मुझे इस मामले में ज्यादा मदद नहीं मिली। populate_obj()
काम करने के लिए मुझे क्या करना चाहिए?
आपको यह वर्णन करने की ज़रूरत है कि आपको कौन सी त्रुटि मिल रही है, या आप अपने परिणामों से कितने परिणाम प्राप्त कर रहे हैं। –
मैं उम्मीद कर रहा था कि अगर कोई मुझे बताएगा कि मुझे कहां रखा जाना चाहिए, जहां मैंने लिखा है ** ** यहां क्या रखा जाना चाहिए? **। इसके अलावा उस तरीके से प्राप्त उपयोगकर्ता ऑब्जेक्ट को पास करने की अनुमति है या नहीं। – consumer