反向使用时,Django 重定向将元组附加到 URL
Django redirect is appending tuple to URL when used reverse
当我使用success_url = reverse_lazy('weatherdata:sample-list')
重定向到的URL是:
http://localhost:8000/weather/('/weather',)
而不是预期的:
http://localhost:8000/weather/
对于某些上下文。这些是我的模块:
main/urls.py
urlpatterns = [
path('weather/', include(('weatherdata.urls', 'weatherdata'), namespace="weatherdata")),
path('admin/', admin.site.urls),
]
weatherdata/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')
你是金色的。
当我使用success_url = reverse_lazy('weatherdata:sample-list')
重定向到的URL是:
http://localhost:8000/weather/('/weather',)
而不是预期的:
http://localhost:8000/weather/
对于某些上下文。这些是我的模块:
main/urls.py
urlpatterns = [
path('weather/', include(('weatherdata.urls', 'weatherdata'), namespace="weatherdata")),
path('admin/', admin.site.urls),
]
weatherdata/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')
你是金色的。