【发布时间】:2021-02-18 07:02:15
【问题描述】:
我已经部署了一个 django 应用程序,该应用程序调用一个 python 文件以将 django 表单上捕获的数据发送到第三方独立服务器。问题是当从 django 表单调用 python 文件时,会导致在浏览器上看到这个错误 -
file: URLs with hostname components are not permitted
Request Method: POST
Request URL: http://127.0.0.1:8000/phone_associate_form/
Django Version: 3.1.3
Exception Type: ValueError
Exception Value:
file: URLs with hostname components are not permitted
Exception Location: E:\INVOKEDID\lib\site-packages\requests_file.py, line 34, in send
这是局部变量的输出
kwargs
{'cert': None,
'proxies': OrderedDict(),
'stream': False,
'timeout': 20,
'verify': False}
request
<PreparedRequest [GET]>
self
<requests_file.FileAdapter object at 0x000001DBB1302B88>
url_parts
ParseResult(scheme='file', netloc='E:', path='/INVOKEDID/NumberRepo/MASTERHANDLER/axlsqltoolkit/schema/current/AXLAPI.wsdl', params='', query='', fragment='')
这是 django 的 pip freeze 输出 -
appdirs==1.4.4
asgiref==3.3.0
attrs==20.3.0
beautifulsoup4==4.9.3
cached-property==1.5.2
certifi==2020.6.20
chardet==3.0.4
defusedxml==0.6.0
diff-match-patch==20200713
Django==3.1.3
django-crispy-forms==1.9.2
django-easy-audit==1.3.0
django-import-export==2.4.0
django-shibboleth-remoteuser==0.12
et-xmlfile==1.0.1
idna==2.10
isodate==0.6.0
jdcal==1.4.1
lxml==4.6.1
MarkupPy==1.14
numpy==1.19.4
odfpy==1.4.1
openpyxl==3.0.5
pandas==1.1.4
psycopg2==2.8.6
python-dateutil==2.8.1
pytz==2020.4
PyYAML==5.3.1
requests==2.24.0
requests-file==1.5.1
requests-toolbelt==0.9.1
six==1.15.0
soupsieve==2.0.1
sqlparse==0.4.1
tablib==2.0.0
urllib3==1.25.11
xlrd==1.2.0
xlwt==1.3.0
zeep==4.0.0
Here is the view-
def phone_associate_form(request, id=0):
if request.method =="POST":
if id==0:
print ('in post block of view')
form = Phone_MAC_Address_Model_Form(request.POST)
print ('get mac address from page')
phone_mac_address = request.POST.get('phone_mac_address')
country = request.POST.get('country_id')
print(country)
return_result=phone_mac_acd_associate_custom(phone_mac_address)
if form.is_valid():
form.save()
return redirect('phone_associate_list')
这是网址-
path('phone_associate_form/', views.phone_associate_form, name='phone_associate_form'),
path('phone_associate_list/', views.phone_associate_list, name='phone_associate_list'),
【问题讨论】:
-
能否附上 urls.py 和视图的代码?还要重新格式化问题中的文本
-
这里是 urls.py 部分 - ` path('phone_associate_form/', views.phone_associate_form, name='phone_associate_form'), path('phone_associate_list/', views.phone_associate_list, name='phone_associate_list '), ` 下面的视图部分 - ` `
-
我认为现在发布视图代码会更好
-
这里是查看代码 - def phone_associate_form(request, id=0): if request.method =="POST": if id==0: print ('in post block of view') form = Phone_MAC_Address_Model_Form(request.POST) print ('get mac address from page') phone_mac_address = request.POST.get('phone_mac_address') country = request.POST.get('country_id') print(country) return_result=phone_mac_acd_associate_custom( phone_mac_address) if form.is_valid(): form.save() return redirect('phone_associate_list')
-
您可以将该代码添加到问题中吗?在评论中是不可读的。如果你不能,我可以为你编辑原始帖子
标签: python django django-rest-framework django-forms