在视图中调用脚本 PYTHON / DJANGO
Call a script within a view PYTHON / DJANGO
我对 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"
我做了一些研究,但没有任何结果
提前感谢您的帮助!
如果有人对我找到的答案感兴趣,我会创建新模型并将结果保存在模型中,然后 运行 使用这些模型而不是变量来编写脚本!干杯!
@csrf_exempt
def register(request):
type_list=request.POST.get('selected_type').split("&")
from_date=request.POST.get('start_date').replace("&","")
to_date=request.POST.get('end_date').replace("&","")
filtertype.objects.all().delete()
n = 0
for item in type_list:
n = n + 1
print(item)
add = filtertype(id=n, transaction_type=item)
add.save()
filterdate.objects.all().delete()
add = filterdate(id=3, start_date=from_date,end_date=to_date)
add.save()
print(type_list,from_date,to_date)
import transaction.query
profiling = transactionprofiling.objects.all()
tmpl = loader.get_template("transaction/index.html")
cont = {'profiling': profiling}
return HttpResponse(tmpl.render(cont))
我对 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" 我做了一些研究,但没有任何结果
提前感谢您的帮助!
如果有人对我找到的答案感兴趣,我会创建新模型并将结果保存在模型中,然后 运行 使用这些模型而不是变量来编写脚本!干杯!
@csrf_exempt
def register(request):
type_list=request.POST.get('selected_type').split("&")
from_date=request.POST.get('start_date').replace("&","")
to_date=request.POST.get('end_date').replace("&","")
filtertype.objects.all().delete()
n = 0
for item in type_list:
n = n + 1
print(item)
add = filtertype(id=n, transaction_type=item)
add.save()
filterdate.objects.all().delete()
add = filterdate(id=3, start_date=from_date,end_date=to_date)
add.save()
print(type_list,from_date,to_date)
import transaction.query
profiling = transactionprofiling.objects.all()
tmpl = loader.get_template("transaction/index.html")
cont = {'profiling': profiling}
return HttpResponse(tmpl.render(cont))