首页 > 解决方案 > 如何将 vue 模板渲染到 django 视图中?

问题描述

首先,我正在创建用户创建问题的问答类型应用程序。如果用户添加了 django API 中存在的相同问题,那么我需要通过模板上的错误。所以这个应用我使用了 vuejs 和 django、DRF 和 webpack。现在我想比较数据库中存在的问题和准备推送问题内容的用户。

#1。如果这不正确,我如何在 vuejs 脚本中进行比较。#2。我们如何将 vuejs 模板渲染到 django 视图中

 return render('request' , QuestionEditor.vue') 

将vue的模板渲染到django中是否正确?

from django.contrib import messages
from .models import Question

def content(request):
    if request.method == 'POST':
        content = request.POST.get('content')

        if Question.objects.filter(content=content).exists():
            messages.warning(request, 'Question already exists')
            return redirect('ask') # ask is nothing but name in the vuejs router file
    else:
        question = Question(content=content)
        question.save()
        messages.success(request, 'Question has been added')
        return redirect('/')
return render(request, '../views/QuestionEditor.vue')

标签: djangovue.jswebpackdjango-rest-frameworkdjango-views

解决方案


推荐阅读