【发布时间】:2019-12-17 00:17:59
【问题描述】:
我是 Python 和 Django 或一般代码的新手
我创建了一个使用 javascript 从 html 模板中获取价值的视图。收集到这些值后,我想运行一个考虑这些新值的脚本
@csrf_exempt
def register(request):
type_list=request.POST.get('selected_type').split("&") #array collected from checkboxes
from_date=request.POST.get('start_date').replace("&","") #date collected
to_date=request.POST.get('end_date').replace("&","") #date collected
import transaction.query #script I want to run
profiling = transactionprofiling.objects.all() #database/model updated with the script
tmpl = loader.get_template("transaction/index.html")
cont = {'profiling': profiling}
return HttpResponse(tmpl.render(cont)) #return the model in the template
定义不起作用,因为它没有保存值“type_list”“from_date”“to_date” 我做了一些研究,但没有任何结果
提前感谢您的帮助!
【问题讨论】:
-
欢迎来到 SO。您实际上是在哪里保存对象?
transaction.query里面有什么?是否出现任何错误? -
事务分析被保存到模型中,其他的暂时只在变量上,我也尝试将它们保存到模型中,但似乎什么都没有保存。
-
code code filterdate.start_date=from_date filterdate.end_date=to_date filterdate().save() -
进入查询我用 SQL 查询更新了名为“transactionprofiling”的表/模型,当我在 query.py 中声明随机变量时,一切似乎都正常
标签: python django import python-import