一、项目简介
1.1 项目博客地址
1.2 https://home.cnblogs.com/longisland/
1.2 项目完成的功能与特色
登陆,注册,博客评论,发表博客,删除博客,修改博客
1.3 项目采用的技术栈
以Django为框架,pycharm为开发工具,使用MySQL为数据库,开发的一款博客网站。
1.4 项目借鉴源代码的地址
https://blog.csdn.net/holysll/article/details/87911218
1.5 团队成员任务分配表
许奕钿 |
登陆,注册 |
王福斌 |
发表博客,删除,修改博客 |
包香龙 |
博客评论,博客主页显示 |
二、项目的需求分析
用户的注册,登陆;
博客的发表,修改和删除;
博客发表评论;
三、项目功能架构图、主要功能流程图
四、系统模块说明
4.1 系统模块列表
1.用户登录注册模块;
2.博客发表模块;
3.博客修改删除模块;
4.博客评论模块
4.2 各模块详细描述(名称,功能,运行截图,关键源代码)
用户登陆:
<div class="col-sm-9">
{% if form.errors %}
<div class="alert alert-danger">你的用户名或密码错误,请重新登录</div>
{% endif %}
</div>
<!-- Form - Login -->
<form method="post" action="{% url ‘login‘ %}" class="form-horizontal">
{% csrf_token %}
<div class="form-group">
<div class="col-sm-9">
<!-- Form field - username -->
<input type="text"
placeholder="用户名"
class="form-control"
name="username">
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<!-- Form field - password -->
<input type="password"
placeholder="密码"
class="form-control"
name="password">
</div>
</div>
<div class="row">
<div class="col-sm-9">
<input type="submit" class="btn btn-primary btn-block" value="登录"/>
</div>
</div>
用户注册:
<form action="" method="post" class="form-horizontal">
{% csrf_token %}
<div class="form-group">
<div class="col-sm-9">
<!-- Errors - username -->
{% if form.username.errors %}
<label class="alert alert-danger">{{ form.username.errors }}</label>
{% endif %}
<!-- Form field - username -->
<input type="text"
placeholder="Username"
class="form-control"
name="username"
required
value="{{ form.username.value|default:"" }}">
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<!-- Errors - password -->
{% if form.password.errors %}
<label class="alert alert-danger">{{ form.password.errors }}</label>
{% endif %}
<!-- Form field - password -->
<input type="password"
placeholder="Password"
class="form-control"
name="password"
required
value="{{ form.password.value|default:"" }}">
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<!-- Errors - first_name -->
{% if form.first_name.errors %}
<label class="alert alert-danger">{{ form.first_name.errors }}</label>
{% endif %}
<!-- Form field - first_name -->
<input type="text"
placeholder="First Name"
class="form-control"
name="first_name"
required
value="{{ form.first_name.value|default:"" }}">
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<!-- Errors - last_name -->
{% if form.last_name.errors %}
<label class="alert alert-danger">{{ form.last_name.errors }}</label>
{% endif %}
<!-- Form field - last_name -->
<input type="text"
placeholder="Last Name"
class="form-control"
name="last_name"
required
value="{{ form.last_name.value|default:"" }}">
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<!-- Errors - email -->
{% if form.email.errors %}
<label class="alert alert-danger">{{ form.email.errors }}</label>
{% endif %}
<!-- Form field - email -->
<input type="text"
placeholder="Email"
class="form-control"
name="email"
required
value="{{ form.email.value|default:"" }}">
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<!-- Submit button -->
<button type="submit" class="btn btn-primary btn-block">注册</NOtton>
</div>
</div>
登陆异常处理:
注册异常处理:
博客发表:
<div class="form-group">
<div class="col-sm-9">
<!-- Errors - title -->
{% if form.title.errors %}
<label class="alert alert-danger">{{ form.title.errors }}</label>
{% endif %}
<!-- Form field - title -->
<input type="text"
placeholder="标题"
class="form-control"
name="title"
value="{{ form.title.value|default:"" }}">
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<!-- Errors - body -->
{% if form.body.errors %}
<label class="alert alert-danger">{{ form.body.errors }}</label>
{% endif %}
<!-- Form fields - body -->
<textarea placeholder="内容"
class="form-control"
name="body">{{ form.body.value|default:"" }}</textarea>
</div>
</div>
<div class="form-group">
<div class="col-sm-9">
<!-- Submit button -->
<button type="submit" class="btn btn-primary btn-block">发表</NOtton>
</div>
</div>
博客修改:
def test_update_post_by_author(self):
self.client.login(username=USERNAME_JOHN, password=PASSWORD_JOHN)
# Empty fields in form
response = self.client.post(self.url, {‘title‘: ‘‘, ‘body‘: ‘‘})
self.assertFormError(response, ‘form‘, ‘title‘, ‘标题不能为空‘)
self.assertFormError(response, ‘form‘, ‘body‘, ‘内容不能为空‘)
# Non-empty fields in form
response = self.client.post(self.url, {‘title‘: ‘Title 3‘, ‘body‘: ‘Lorem ipsum‘})
self.assertRedirects(response, reverse(‘blog:post‘, kwargs={‘pk‘: self.test_post_john.id}))
博客删除:
def test_delete_post_by_author(self):
self.client.login(username=USERNAME_JOHN, password=PASSWORD_JOHN)
response = self.client.post(self.url)
self.assertRedirects(response, reverse(‘blog:home‘))
博客评论:
def test_create_comment_by_logged_user(self):
self.client.login(username=USERNAME_JOHN, password=PASSWORD_JOHN)
# Empty fields in form
response = self.client.post(self.url, {‘body‘: ‘‘})
self.assertFormError(response, ‘form‘, ‘body‘, ‘评论不能为空.‘)
# Non-empty fields in form
response = self.client.post(self.url, {‘body‘: ‘Lorem ipsum‘})
self.assertRedirects(response, reverse(‘blog:post‘, kwargs={‘pk‘: self.test_post_john.id}))
五、项目总结
5.1 特点
1.用户操作博客简单;
2.持续更新:用户可以更新自己的博客内容;
3.开放互动:用户可以在博客评论区进行评论互动;
4.展示个性;
5.2 不足之处
整个网站的逻辑还不够严密,关于用户互动的功能,博客发表的内容还不够完善,页面设计不够新颖。
原文:https://www.cnblogs.com/longisland/p/12045344.html