The correct url is:
url(r'^xray/(?P<id>\d+)/(?P<image_name\w+\.\w{3})$', mypil.views.edit_xray)
You should put the pattern in the parentnesses.
質問
I want to construct the following url
domain/edit/xray/<id>/<image_name>
where id is a model's id and image_name is the name of an image.
I have an app that will handle image editing with its own views lets say it mypil
mypil.views
def edit_xray(request, id, image_name):
....code to get image by name
....model by id and edit image using PIL
model = Model.objects.get(pk=id)
project/urls.py
url(r'^edit/', include(mypil.urls))
mypil.urls
url(r'^xray/(?P<id>)\d+/(?P<image_name>)\w+\.\w{3}$', mypil.views.edit_xray)
But when i try to view edit/xray/1/image.jpg (both id and image exist) i encounter this problem.
invalid literal for int() with base 10: ''
and the traceback shows me that line above
model=Model.objects.get(pk=id)
Does the empty string('') mean that it doesn't parse the id correctly from the URL? Isn't my url pattern correct?
EDIT: Damn my eyes....needed to put \d+ and the image reg pattern inside the parentheses
url(r'^xray/(?P<id>\d+)/(?P<image_name>\w+\.\w{3})$,...)
Sorry for posting a question...(How do i delete my own questions?)
解決
The correct url is:
url(r'^xray/(?P<id>\d+)/(?P<image_name\w+\.\w{3})$', mypil.views.edit_xray)
You should put the pattern in the parentnesses.