如何在 get 方法中发送标题值?
getBooksDetails.html
<a href="getBookDetails" style="text-decoration: none">
<h4 class="overflow title" title="{{ book.title.upper }}">{{ book.title.upper }}</h4>
</a>
urls.py
urlpatterns = patterns('',
(r'^index', 'views.index'),
(r'getBookDetails', 'views.getBookDetails'),
)
我试图在这个方法中打印标题的值只是为了确认值是否到来。有人可以帮助我,如何在 GET 方法中发送和获取值。
views.py
def getBookDetails(request):
print request.GET // how to get title value here from get method
return render_to_response('getBookDetails.html')
最佳答案
您可以在URL
中发送数据:
例如,假设我们有一个像这样的网址:
http://localhost:8000/hi?id="bye"
您可以通过两种方式获取Django
中的数据:
request.GET['id']
或
request.GET.get('id', 'default value')
关于python - 如何通过get方法获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17691385/