0

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?)

2
  • Don't delete it, it's not a bad question. Someone might do the same mistake again Commented Oct 29, 2013 at 10:41
  • Is it really? Just not being cautious enough lol :) Commented Oct 29, 2013 at 11:57

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Keeping the trailing slash is a good practice, in my opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.