既然有登录登出,那么用户的注册肯定也是少不了的。注册表单类用户注册时会用到表单来提交账号、密码等数据,所以需要写注册用的表单/userprofile/forms.py:/userprofile/forms.py
...
# 注册用户表单
class UserRegisterForm(forms.ModelForm):
# 复写 User 的密码
password = fo...
用户管理用户数据可以说是大部分网站最重要的资产。用户管理就是对用户数据进行增删改查等操作的功能,自然也就非常的重要了。本章开始学习用户管理的内容,首先从用户登录开始。在Django中用app来区别不同功能的模块,达到代码隔离和复用。因为用户管理和博客文章的功能不同,因此需要新建一个专门的app。进入虚拟环境,运行startapp指令创建新的app:python manage.py start...
目前为止我们已经完成了文章的新建、删除以及查看,还剩最后一项,即对已经完成的文章进行修改。实际上修改文章与新建文章有点类似,不同的地方有两点:修改是在原有文章的基础上,因此需要传递 id 指明具体需要修改的文章加载页面时需要将旧的内容作为默认值填写到表单中,因此需要将文章对象传递到html中按照这个思路,接下来先写视图函数。视图函数在ariticle/views.py中增加修改文章的视图函数...
既然有了写文章的功能,那当然也必须要有删除文章的功能了。不安全的方式有了之前的学习做铺垫,删除文章实现起来就比较简单了。首先增加一个视图函数:article/views.py
...
# 删文章
def article_delete(request, id):
# 根据 id 获取需要删除的文章
article = ArticlePost.objects.get(id=i...
前面我们已经学会如何用Markdown语法书写文章了。但是还有问题呀。之前写文章都是在后台中进行的,万一有别的普通用户也要发表文章怎么办?万一我想拓展些后台中没有的提交验证功能又怎么办?本章即讲述如何在前台中提交新的文章,以便满足开发者各种各样的特殊需求。Forms表单类在HTML中,表单是在 <form>...</form> 中的一些元素,它允许访客做类似输入文本、...