django - 如何将 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')
解决方案
推荐阅读
- android - 如何获得模拟电话管理器服务android
- html - 我怎样才能让4个div彼此相邻
- android - 滑动/拉动以刷新 Android RecyclerView
- javascript - Javascript JQuery倒数计时器循环
- ms-word - Word Web 插件从服务器页眉/页脚加载整个文档
- r - 如何遍历行,然后在每一行内循环遍历列,直到找到 NA,然后提取前一列的值
- json - 创建 JSON - Angular 5
- python - 将 help() 函数内容的输出重定向到文件
- java - 春季调度,调度程序仅在第一天晚上 11:57 运行,而不是在 Spring MVC 中每天运行
- heroku - 通过 Travis-CI 部署到 Heroku 的问题