django - Django重定向在使用反向时将元组附加到URL
问题描述
当我使用success_url = reverse_lazy('weatherdata:sample-list')
它重定向到的 URL 是:
http://localhost:8000/weather/('/weather',)
而不是预期的:
http://localhost:8000/天气/
对于某些上下文。这些是我的模块:
主/urls.py
urlpatterns = [
path('weather/', include(('weatherdata.urls', 'weatherdata'), namespace="weatherdata")),
path('admin/', admin.site.urls),
]
天气数据/urls.py
urlpatterns = [
path('', WeatherSampleList.as_view(), name='sample-list'),
path('takesample', WeatherByLocationFormView.as_view(), name='take-sample'),
]
在我的 weatherdata/views.py
class WeatherByLocationFormView(FormView):
[...]
success_url = reverse_lazy('weatherdata:sample-list'),
解决方案
你有一个杂散的逗号
success_url = reverse_lazy('weatherdata:sample-list'),
这与
success_url = (reverse_lazy('weatherdata:sample-list'),)
这是你看到的元组。
做了
success_url = reverse_lazy('weatherdata:sample-list')
你是金色的。
推荐阅读
- python-3.x - 覆盖列表(对象)
- python - 如果用户输入字符串而不是整数,我如何使代码重新运行
- java - 如何将其定向到正确的位置?
- c# - 如何以编程方式更改IP地址?
- javascript - Alexa 技能 .getResponse() 有什么作用?
- ruby - Ruby 递归索引/搜索方法(使用中间比较)返回不正确的索引值
- javascript - How to sink field value to nested JSON with lodash
- json - 如何使Vue显示来自json文件的本地路径的图像
- ibm-watson - 是否可以在 Watson 助手中获取 Slack 用户名作为实体?
- python-3.7 - 为什么在python中更新一个实例类变量会同时更新其他不相关的变量?