【一】后端
class ArticleAdd(View):
def get(self,request, *args, **kwargs):
# article_obj_all = Article.objects.filter(blog=request.user.blog)
category_obj_all = CategoryClass.objects.filter(blog=request.user.blog)
tag_obj_all = CategoryTag.objects.filter(blog=request.user.blog)
return render(request,'add_article.html',locals())
def post(self,request, *args, **kwargs):
...
【二】前端
{% extends 'backend.html' %}
{% block add_article %}
<div class="panel panel-success" style="margin-top: 20px">
<div class="panel-heading">
<h5>添加文章</h5>
</div>
</div>
<form action="" method="post">
{% csrf_token %}
<div class="form-group">
<label for="">文章标题:</label>
<input type="text" name="article_title" class="form-control">
</div>
<div class="form-group">
<label for="">文章内容:</label>
<textarea name="article_content" id="article_content" cols="30" rows="10" class="form-control"></textarea>
</div>
<div class="form-group">
<label for="">文章分类:</label>
<select class="form-control" id="article_class" name="article-class">
{% for category_obj in category_obj_all %}
<option value="{{ category_obj.pk }}">{{ category_obj.name }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="">文章标签:</label>
<select class="form-control" id="article_class" name="article-class" multiple >
{% for tag_obj in tag_obj_all %}
<option value="{{ tag_obj.pk }}">{{ tag_obj.name }}</option>
{% endfor %}
</select>
</div>
</form>
{% endblock %}