I have a url.
**"/deals/image/"+name**
name is a variable which gives the image name.
The view catering to this url is
def image(request,name = None):
if name == None:
name = "3gmjr0kme6_coffee-art.jpg"
else:
name = str(name)
this_directory = settings.PROJECT_ROOT
url = this_directory+"\\templates\\media\\images\\photos\\"
full =url+name
image_data = open(full, "rb").read()
return HttpResponse(image_data, mimetype="image/png")
The problem that I am facing is that it is unable to get this view because of the dot “.” i.e. “/deals/image/some_image.jpg” is not able to find the view. How can i accout for the “.”? or am i doing something wrong?
urls file is as follows
url(r'^image/(\w+)$','image'),
Any help will be highly appreciated.
Change the URL configuration to something like this:
[...]part is a character set. It will match all characters inside.\wis used to match normal characters (A to Z and a to z), digits and the underscore “_”.\.matches a literal dot.+means one or more of the previous expression.When the
\wand\.is put together inside a character set ([]), it will match all characters and digits, as well as underscore and the dot. Putting the+after means that there has to be at least one character in the set.