django 富文本 登陆验证及跳转 及POST

1.
CKEDITOR
templates模板中
filter过滤器safe可讲html富文本进行渲染

    <p>{{ one_article.content|safe }}</p>

2.
添加富文本编辑器

<head>
    <script src="/static/plugins/ckeditor/ckeditor.js"></script>
</head>

    <textarea id="id_content"></textarea>

<body>
    <script>
        CKEDITOR.replace("id_content");
    </script>
</body>

3.
验证登录、及登录跳转
settings中设置登录跳转路径

settings.py

LOGIN_URL = '/signin/'

views.py

from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login, logout



@login_required
#@login_required(login_url='/signin')也可以这样跳转


def new_article(request):
    if request.method == "GET":

4.
POST GET对应方法。

@login_required
def new_article(request):
    if request.method == "GET":
        article_form = form.ArticleModelForm()
        return render(request, 'bbs/new_article.html', {
            'category_list':category_list,
            'article_form':article_form,
        })

    elif request.method == "POST":
        print(request.POST)
        article_form = form.ArticleModelForm(request.POST, request.FILES)
        if article_form.is_valid():
            data = article_form.cleaned_data
            #cleaned_data类似对象,无法直接编辑。
            data['author_id'] = request.user.userprofile.id
            article_obj = models.Article(**data)
            article_obj.save()
            return HttpResponse('new article saved!')

        else:
            return render(request, 'bbs/new_article.html', {
            'category_list': category_list,
            })

5.
post传输文件注意事项
enctype=”multipart/form-data”

        <form method="post" enctype="multipart/form-data">{% csrf_token %}
            {{ article_form }}
            <input type="submit" class="btn btn-success pull-right" style="margin-top: 20px" value="发布">
        </form>

接收部分

article_form = form.ArticleModelForm(request.POST, request.FILES)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值