【发布时间】:2021-09-29 14:57:18
【问题描述】:
当我使用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),
]
天气数据/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'),
【问题讨论】:
-
去掉结尾的逗号。
标签: django django-urls