python - Django 1.6 Profile pic not showing -
i'm trying display picture 1 of models in template, run following error. seems there error in views i'm not sure change. feel i'm passing right parameters it's not working.
traceback: file "/library/python/2.7/site-packages/django/core/handlers/base.py" in get_response 114. response = wrapped_callback(request, *callback_args, **callback_kwargs) file "views.py" in showdocprofile 51. return render(request,'meddy1/docprofile.html',{'doctor': profile}) file "/library/python/2.7/site-packages/django/shortcuts/__init__.py" in render 53. return httpresponse(loader.render_to_string(*args, **kwargs), file "/library/python/2.7/site-packages/django/template/loader.py" in render_to_string 169. return t.render(context_instance) file "/library/python/2.7/site-packages/django/template/base.py" in render 140. return self._render(context) file "/library/python/2.7/site-packages/django/template/base.py" in _render 134. return self.nodelist.render(context) file "/library/python/2.7/site-packages/django/template/base.py" in render 840. bit = self.render_node(node, context) file "/library/python/2.7/site-packages/django/template/debug.py" in render_node 78. return node.render(context) file "/library/python/2.7/site-packages/django/template/defaulttags.py" in render 447. six.reraise(*exc_info) file "/library/python/2.7/site-packages/django/template/defaulttags.py" in render 433. url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) file "/library/python/2.7/site-packages/django/core/urlresolvers.py" in reverse 532. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs)) file "/library/python/2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix 452. (lookup_view_s, args, kwargs, len(patterns), patterns)) exception type: noreversematch @ /docprofile/1/ exception value: reverse 'getdocprofilepicture' arguments '(1,)' , keyword arguments '{}' not found. 0 pattern(s) tried: []
here template i'm trying load picture
{% include "meddy1/header.html" %} {% load staticfiles %} <br> <br> <h1>{{doctor.name}}'s profile</h1> <img src="{% url 'getdocprofilepicture' doctor.id %}"> {% include "meddy1/footer.html" %}
here views.py
def getdocprofilepicture(request, id): d = doctor.objects.get(id=doctor_id) return httpresponse(d.profile_pic.read())
here models.py
class doctor(models.model): name = models.charfield(max_length=30) specialization = models.foreignkey(specialization) clinic = models.foreignkey(clinic) seekers = models.manytomanyfield(doctorseeker, through='review') language = models.manytomanyfield(language) education1 = models.charfield(max_length=100) education2 = models.charfield(max_length=100, null = true) gender_choices = ( ('m', 'male'), ('f','female'),) gender = models.charfield(max_length=5, choices = gender_choices, null=true) profile_pic = models.imagefield(upload_to='uploads/', null=true) statement = models.textfield(null=true) affiliation = models.charfield(max_length=100, null = true)
urls.py
url(r'^docprofile/(?p<id>\d+)/$', views.showdocprofile, name='showdocprofile'), url(r'^getdocprofileicture/ (?p<doctor_id>\d+)/$', views.getdocprofilepicture, name='getdocprofilepicture'),
you don't need view this, call attribute image:
<img src="{{ media_url}}{{ doctor.profile_pic.url }}">
Comments
Post a Comment