新建随笔布局的功能

【一】后端

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 %}

image-20240325122930996

posted @ 2024-03-29 16:55  -半城烟雨  阅读(3)  评论(0编辑  收藏  举报