用 Django admin 开发一个简单的数据录入网站,客户需要自己创建一些用户, Django admin 默认的 form 太复杂而且要两步才能完成,如何一步搞定?
1
wenbinwu 2015-09-22 15:12:40 +08:00
你自己写一个注册页面?
|
3
cnleoyang 2015-09-22 15:27:38 +08:00 via iPad
自己写吧,共享一个代码片段供参考
https://gist.github.com/anonymous/875d35faf9c8eb3ffa84 |
5
gevin 2015-09-22 16:49:09 +08:00
我也提供一个用户注册的实现
``` class RegisterView(View): template_name = 'accounts/simple_form.html' def get(self, request, form=None): if not form: form = forms.RegisterForm() data = {'title':'Register', 'form':form, 'btn_name':'Register'} return render(request, self.template_name, data) def post(self, request): form = forms.RegisterForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] email = form.cleaned_data['email'] password = form.cleaned_data['password'] user = User.objects.create_user(username, email, password) user.save() msg = 'Successfully Registered' messages.add_message(request, messages.SUCCESS, msg) url = reverse('accounts:login') return redirect(url) else: return self.get(request, form) ``` |
6
gevin 2015-09-22 16:50:57 +08:00
|