简体   繁体   English

django urls.py中的GET数据未传递到视图

[英]GET data in django urls.py not passing to view

I'm having a tough time figuring out how to parse my URL GET data and send it to the right view. 我很难弄清楚如何解析我的URL GET数据并将其发送到正确的视图。

I have a search view that only has a search input: 我有一个仅包含搜索输入的搜索视图:

template/search.html template / search.html

<form action="http://domain.com/schools/search/" method="GET" >
    <input type="text" name = "q_word">
    <input type="submit" value="Search"/>
</form>

When a user enters in a search term, I want to send that data to another view to parse and use in a geocoding function I wrote. 当用户输入搜索字词时,我想将该数据发送到另一个视图以进行解析并用于我编写的地理编码功能中。 Here is a look at my urls.py: 看一下我的urls.py:

url(r'^schools/search/$', school_views.find_school, name="find_school"),
url(r'^schools/search/(?P<address>[\w ]+)$', school_views.geo_locate, name="geo_locate"),

I want to grab the GET data from a URL (after they've entered in the info), and pass it as an address argument to my school_views.geo_locate function. 我想从URL中获取GET数据(将它们输入信息后),并将其作为地址参数传递给我的school_views.geo_locate函数。

This set up works great when you manually type out a URL like: schools/search/150%20main%20Street 当您手动输入以下网址时,此设置非常有用schools / search / 150%20main%20Street

But when a user submits any form data, the URL passed is /schools/search/?q_word=150+west+main and I'm just kicked back to my search template. 但是,当用户提交任何表单数据时,传递的URL是/ schools / search /?q_word = 150 + west + main ,我被踢回到搜索模板。

I think my regex needs to be tweaked in my second url argument, but I just keep returning to the search page after submission, with no data going to my geo_locate view. 我认为我的正则表达式需要在第二个url参数中进行调整,但是提交后我一直保持返回搜索页面的状态,没有数据进入geo_locate视图。 Is this a URLs problem? 这是网址问题吗?

GET data is not passed in the URL parameters. GET数据未在URL参数中传递。 Don't try to capture it in the regex. 不要试图在正则表达式中捕获它。 Just get it from request.GET inside the view. 只需从request.GET获取即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM