这是我第一次将应用程序部署到Azure应用服务器。 我遇到一个问题,我的参数正在进行url编码,并且在python函数中将其打印出来时,它用'%20'替换空格。传递请求时,我没有在JavaScript中使用encodeURI()。 看起来这仅在部署到Azure时发生。一切都能在本地和Linux服务器上正常运行。我需要更新配置以在Azure上运行django应用程序吗?
urls.py
path('person/<name>/', views.person, name="person"),
我也尝试过使用url而不是正则表达式的路径,但也无法使用。
url('person/(?P<name>[^/]+)/', views.person, name="person"),
请求网址:“ GET” / person / John%20Doe /
views.py
def dashboard(request, name)::
print(name)
# expected John Doe
# actual John%20Doe
return render(request, 'person.html', {'name': name})
person.html 我正在使用django模板来呈现名称,它显示为“ John%20Doe”而不是“ John Doe”
<h3>{{ name }}</h3>
运行FASTCGI作为处理程序的IIS Web服务器
web.config
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated web.config for Microsoft Azure. Remove this comment to prevent
modifications being overwritten when publishing the project.
-->
<configuration>
<appSettings>
<add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
<add key="PYTHONPATH" value="D:\home\site\wwwroot" />
<add key="DJANGO_SETTINGS_MODULE" value="myapp.settings" />
<add key="WSGI_LOG" value="D:\home\LogFiles\1new1.log"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<handlers>
<add name="Python FastCGI" path="handler.fcgi" verb="*" modules="FastCgiModule"
scriptProcessor="D:\home\python364x64\python.exe|D:\home\python364x64\wfastcgi.py"
resourceType="Unspecified" requireAccess="Script" />
</handlers>
<rewrite>
<rules>
<rule name="Configure Python" stopProcessing="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
</conditions>
<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
本地Python v3.6.3, Azure Python v3.6.4, Django v2.1.12,