Saturday, September 23, 2017

Re: capturing url pattern from html forms

Unfortunately, I didn't show my entire URLpatterns list, and the ^item/$  seems to interfere with the ^$ of the previous:  Any suggestions for a work around? thanks again. 

from django.conf.urls import include, url
from django.contrib import admin
from rest_framework.urlpatterns import format_suffix_patterns
from durham_app import views

urlpatterns = [
# Examples:
url(r'^admin/', include(admin.site.urls)),

url(r'^$', views.index, name='index'),
url(r'^item/$', views.item_detail, name='item_detail'),
url(r'^items/', views.ItemList.as_view()),
]

urlpatterns = format_suffix_patterns(urlpatterns)





On Saturday, September 23, 2017 at 3:41:16 PM UTC-4, Daniel Roseman wrote:


On Saturday, 23 September 2017 19:48:37 UTC+1, Mel DeJesus wrote:

Hi - 

If the number '1' is submitted with the form below, the following url is created:  http://localhost:8000/item/?id=1

But I continually get a page not found.  How can I style the regex in the urlpatterns so that this url registers?  Thanks. 

<form id="form" form action = "item/" method="get">
Item Name:<br>
<input id="entry" type="text" name="id"><br>
<br><br>
<input type="submit" value="Submit">
</form>

I'm attempting to capture here: 

urlpatterns = [
# Examples:
url(r'^admin/', include(admin.site.urls)),
# url(r'^item\/\?id=(?P<id>\d+)/', views.item_detail, name='item_detail'),
url(r'^item/(?P<id>\d+)/', views.item_detail, name='item_detail'),
# JSON files




GET parameters are not captured in URL patterns. Just accept `^item/$` and get the data inside the view via `request.GET['id']`.
-- 
DR. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f4f72339-6051-4c8e-89e7-f2ac28d1ec77%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment