django-templates

Trying to create a tuple of objects create an object and a queryset

♀尐吖头ヾ 提交于 2019-12-11 16:05:13
问题 I need to iterate through a tuple in the template, but from the code i've built i am getting a tuple of an object (album) and a queryset (photo). The problem is how do i iterate over them now in the template? models: class Album(models.Model): title = models.CharField('כותרת', max_length=100, db_index=True) created = models.DateTimeField('תאריך פרסום', auto_now_add=True) creator = models.ForeignKey(User, related_name='galleries_creator', verbose_name='נכתב ע"י') class Photo(models.Model):

Problem with serving pictures in Django

落爺英雄遲暮 提交于 2019-12-11 16:05:10
问题 I'm trying to create my first site in django and I've run into a problem. I'm trying to serve pictures,but it isn't working correctly. I have it set up in the following way: In settings.py: MEDIA_ROOT = 'C:/Users/John/Documents/My Dropbox/Infostuff/filmsite/media/' MEDIA_URL = 'localhost:8000/static/' ADMIN_MEDIA_PREFIX = '/admin-media/' In urls.py: (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), It looks like this in the template page: <img

Tree Structure (Foreign Keys to itself) and templates

随声附和 提交于 2019-12-11 15:27:35
问题 I have a tree structure for Categories. Categories with a Foreign key that is referring to itself. class Category(MetaData): parent = models.ForeignKey('self', blank=True, null=True, verbose_name='parent category', on_delete=models.CASCADE) name = models.CharField(max_length=255) description = models.TextField() Because I don't know the depth of the categories tree(can't use for) I need to use a recursive function: def cat_for_parents(self, cat_obj): ... if cat_obj.parent_id: p = cat_obj

Django & static files while Debug mode is ON

六月ゝ 毕业季﹏ 提交于 2019-12-11 15:13:21
问题 i have some trouble with static files (images) in templates while Debug is set to True: images are not showed. here is the code of some settings and templates: http://dpaste.com/594183/ with these settings, the printed html doesn't contain the right path to static files. In any case i remember some time ago that even with the right path images are not showed, so maybe the problem is not the path. thanks, Luke 回答1: Where do you put your static files? In a new Django, you should keep them

display dictionary file inside for loop in django template

南笙酒味 提交于 2019-12-11 14:24:56
问题 I have the following dictionary: d = {'21': 'test1', '11': 'test2'} {% with '18 17 16 15 14 13 12 11 21 22 23 24 25 26 27 28' as list_upper %} {% for x in list_upper.split %} {% if x in dental_position %} <input type="text" placeholder = "{{ x }}" class="form-control" name="tooth[]" value="{{display dict.value here}}"> {% else %}<input type="text" placeholder = "{{ x }}" class="form-control" name="tooth[]"> {% endif%} {% endfor %} I want to display the d[value] inside input text value

How to enroll custom user as students in django

吃可爱长大的小学妹 提交于 2019-12-11 14:24:15
问题 I have django course model and custom user as students I added some course for logged student, Now i need to show the profile of user or student and his course in student_profile.html here is my model for course class Course(models.Model): students = models.ManyToManyField('Profile', blank=True) Course_Name = models.CharField(max_length=200) Duration_Time = models.CharField(max_length=50) Course_Fee = models.IntegerField() Discount_Fee = models.IntegerField() Course_Image = models.FileField()

If x in <listOfModels.field> syntax

点点圈 提交于 2019-12-11 13:47:18
问题 I have a model X with a ManyToMany field Y, my query returns a list of X's, How do I do something like: {% if A in X.Y %} Test {% endif %} EDIT: X is still a querySet (I'm not iterating the set). Thanks in advance, 回答1: You're pretty much there. You just have to return an actual queryset: {% if A in X.Y.all %} Test {% endif %} UPDATE (based on comment) That is not possible with template code, you need to do a filter, and the Django templating language doesn't allow passing parameters to

functions in django templates

半腔热情 提交于 2019-12-11 13:38:13
问题 Does django templates support functions? Can I write them inline within the template? If I can, how? 回答1: No. The idea of Django templates is that they only display information (more or less). More complicated constructs (like functions) must be defined elsewhere. But, you can create your own template tags or template filters (in Python code) and then use them in your template. They kind of act like functions. Their definition is not within your template, though. You can read about it in

How to redirect from Django views to a specific view of angular JS

只愿长相守 提交于 2019-12-11 13:19:50
问题 I am working on something which has combo of Django and Angular JS. As the word goes, it little tricky to mix these two. I have everything working fine and so i decided to apply User Authentication. I have applied @login_required which redirects user to login page if not logged in , before checking out. urls.py url(r'^checkout/$','ecommerce.views.checkout'), views.py @login_required def checkout(request): return render_to_response('#checkout0',content_type="text") app.js .when('/checkout0', {

How to display value of a field in a *linked* table, in a Django template?

耗尽温柔 提交于 2019-12-11 12:23:03
问题 I am creating a demo Django website where you browse Billy Joel's albums . You click on an album to view all songs. (If it happens to be on: http://104.131.200.120/albums/all/ --there's hardly any data at the moment. Only one song in Cold Spring Harbor, none in An Innocent Man) I can't figure out how to display the song name in the album page. It can tell if there is a song, because Cold Spring Harbor prints out an empty "name/description" line, and An Innocent Man doesn't. Here's the view