我试着点击http://127.0.0.1:8000/main/electronics/switch/
中的一个按钮来调用getCommodityCommentDetail
来做一些事情,然后重定向到另一个页面commodityInfoPage
。你知道吗
让我困惑的是,页面总是在初始页面中显示相同的内容,尽管url已经更改为http://127.0.0.1:8000/main/comments/1/
。你知道吗
经过测试,我发现commodityInfoPage
在视图.py不打电话。我花了很长时间寻找解决办法,但都失败了。那我怎么修呢?你知道吗
你知道吗网址.py地址:
app_name = 'main'
urlpatterns = [
# eg:127.0.0.1:8000/main/
path('', views.index, name = 'index'),
path('getCommodityInfo/', views.getCommodityInfo, name = 'getCommodityInfo'),
path('getCommodityCommentDetail/', views.getCommodityCommentDetail, name="getCommodityCommentDetail"),
path('<str:category>/<str:searchKey>/',views.commodityInfoPage, name = 'commodityInfoPage'),
path('comments/<str:commodityId>/', views.commodityCommentPage,name = 'commodityCommentPage'),
]
你知道吗视图.py地址:
def getCommodityCommentDetail(request):
if request.method=="POST":
commodityId = request.POST.get("commodityId")
# scrapy module is waiting implementation
#
return HttpResponseRedirect(reverse('main:commodityInfoPage',args=(commodityId)))
def commodityCommentPage(request, commodityId):
print("enter commodityCommentPage")
commentList = JDCommentDetail.objects.all()
context = {'commentList':commentList}
return render(request,'main/commodityCommentPage.html',context)
模板:
<form action="{% url 'main:getCommodityCommentDetail'%}" method="POST">
{% csrf_token %}
<input class="hidden" value="{{commodity.id}}" name="commodityId">
<button type="submit" class="btn btn-default" >review</button>
</form>
问题是
comments/1/
与commodityInfoPage
URL模式匹配。你知道吗您可以通过更改URL模式使其不发生冲突,或者将
commodityCommentPage
URL模式移到commodityInfoPage
模式上方来解决此问题。你知道吗请注意,如果您对模式重新排序,那么如果类别为“comments”,您将无法查看
commodityInfoPage
。你知道吗相关问题 更多 >
编程相关推荐