如何传递参数“request”?从脚本到视图的功能? [英] How can I pass the parameter "request" from a script to a view's function?
问题描述
我有一个假装在我的网站上创建表单并接收响应的脚本,我们称之为script.py。
此脚本需要调用views.py中的函数。 />
I have a script which pretend to create a form in my site and receive the response, let's call it script.py.
This script needs to call a function in views.py:
opc = newproject.views.Menu_Options(request, ask, Options)
这个函数需要使用request.POST,所以需要接收request作为参数。
问题是:
脚本。 py不知道什么是请求。我导入了这个:
This function needs to use request.POST, so needs to receive "request" as parameter.
The problem is:
Script.py doesn't know what is "request". I imported this:
import newproject.views
import django
from django.http import request
我运行项目但是忽略参数request并给了我这行中的错误:
I ran the project but simply ignored the parameter "request" and gave me an error in this line:
opc = newproject.views.Menu_Options(ask, Options)
Exception Type: TypeError at /
Exception Value: Menu_Opctions() missing 1 required positional argument: 'Options'
我输入了错误的请求吗?
在views.py中是否有任何其他方法可以在函数中导入对象请求而不将其作为参数传递?
先谢谢! :)
我尝试了什么:
我试图导入这个:
Did I import a "wrong request"?
Is there any other way in views.py to import in a function the object "request" without passing it as parameter?
Thanks in advance! :)
What I have tried:
I tried to import this:
import newproject.views
import django
from django.http import request
到Script.py但似乎无法正常工作
to Script.py but don't seems to work
推荐答案
我修好了!我意识到当我调用脚本主要功能时,我忘记传递request参数。这就是为什么我的外部脚本不知道请求是什么。
I fixed it! I realised that I forgot to pass the "request" parameter when I call my script main funcion. That's why my external script "didn't know" what "request" was.
这篇关于如何传递参数“request”?从脚本到视图的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!