vt2*_*253 1 django django-templates django-urls django-views
我有一种情况,希望你能帮助我.我已经阅读了一些关于获取SO current_url和 url TEMPLATE_CONTEXT_PROCESSORS(最相关)的当前url路径的帖子和答案.但它似乎不适合我想做的事情.我有一个观点:
def fish_search(request):
    args = {}
    #irrelevant code here
    args['fishes'] = fishes
    args['current_path'] = request.get_full_path()
    return render_to_response('ajax_search.html', args)
在我的ajax_search.html中:
<a id="search-results" href="{{ current_path }}"></a>
和base.html:
div id="search-results" ></div>
Javascript会将搜索结果转储到base.html.并且base.html在fishMarket.html,fishDictionary.html,fishRumour.html等中进行了扩展.所以,遗憾的是,显示的路径都是"/ search /"
我希望路径是/ fishMarket /如果我从fishMarket.html搜索,/ fishDictionary /应该出现,如果我从fishDictionary.html搜索,同样,/ fishRumour /如果我从fishRumour.html搜索.有没有人遇到过这种情况?你是怎么解决这个问题的?我对django比较新,所以请愚蠢地解决这个问题.
我非常感谢你的帮助.非常感谢!
而不是使用request.get_full_path(),它将为您提供搜索视图的路径,而是使用HTTP标头中的referrer.
你可以用它 request.META['HTTP_REFERER']
| 归档时间: | 
 | 
| 查看次数: | 11335 次 | 
| 最近记录: |