Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Django: How to pass object/object id to another template
- def list(request):
- listings = listing.objects.all()
- return render_to_response('/../templates/listings.html',{'listings':listings})
- def detail(request, id):
- #listing = listing.objects.filter(owner__vinumber__exact=vinumber)
- return render_to_response('/../templates/listing_detail.html')
- {% for listing in object_list %}
- <!--<li> {{ listing.title }} </li>-->
- <a href="{{ listing.id }}">{{ listing.title}}</a><br>
- {% endfor %}
- {{ id }}
- # example model
- class Example(models.Model):
- name = models.CharField("Name", max_length=255, unique=True)
- #more model fields here
- #the permalink decorator with get_absolute_url function
- @models.permalink
- def get_absolute_url(self):
- return ('example_view', (), {'example_name': self.name})
- #example view
- def example_view(request, name, template_name):
- example = get_object_or_404(Example, name=name)
- return render_to_response(template_name, locals(),
- context_instance=RequestContext(request))
- #example urls config
- url(r'^(?P<name>[-w]+)/$', 'example_view', {'template_name': 'example.html'}, 'example_view')
- <a href={{ example.get_absolute_url }}>{{ example.name }}</a>
- def detail(request, id):
- l = listing.objects.get(pk=id)
- return render_to_response('/../templates/listing_detail.html', {'listing':l})
Advertisement
Add Comment
Please, Sign In to add comment