django-templates

Django - passing a variable from a view into a url tag in template

依然范特西╮ 提交于 2019-12-08 09:29:10
问题 First of all, I apologize for the noobish question. I'm very new to Django and I'm sure I'm missing something obvious. I have read many other posts here and have not been able to find whatever obvious thing I am doing wrong. Thanks so much for any help, I am on a deadline. I am using Django 1.6 with Python 2.7. I have one app called dbquery that uses a form to take data from the user and query a REST service. I am then trying to display the results on a results page. Obviously there is more

How do include a dynamic template from another app in Django?

ぐ巨炮叔叔 提交于 2019-12-08 08:22:39
问题 I currently have two apps: app1/ app2/ templates/ app1.html app2.html In app1.html, I'm including app2.html: <!-- app1.html --> {% include "app2.html" %} app2 has some dynamic content: <!-- app2.html --> {% app2_value %} When I display app1.html, the value app2_value doesn't show up. What's the best way to handle the above in Django? 回答1: Django doesn't really process dynamic including like PHP or other languages do. Instead, you should have a base template, and use template inheritance and

How do I initiate values for fields in a form for editing in a template

泪湿孤枕 提交于 2019-12-08 07:50:57
问题 I understand that you can use the initiate parameter for a Form class from this question. I am creating an edit form and I'm trying to figure out how to initiate values from a pre-existing object. Do I do it in the template level or in the view level (I don't even know how to do it in the template level)? Or maybe I need to pass the actual object to the form and initiate in the form level? What is the best practice? EDIT: For @Bento: In my original Form , I'm doing something like this class

Django template object property lookup with a dynamic variable name

谁说我不能喝 提交于 2019-12-08 07:42:41
问题 I have a table with user, rank, squat, deadlift, benchpress, Clean and Jerk and Snatch. The ranking system will rank any number of combinations from just total amount Squated, to total amount benchpressed and deadlifted to the total amount lifted across all five disciplines. As you can see there is a huge number of available combinations that a user can check their rankings by. While i have as yet to painstakingly add all these ranking combinations to my database i have done the main 5 ie SQ

Can Django child template create new block as hook

故事扮演 提交于 2019-12-08 06:58:47
问题 I have the following scenario: base.html: {% block content %}{% endblock %} child.html: {% extends 'base.html' %} {% block content %} <p>Overriding content</p> {% endblock %} {% block child_block %}{% endblock %} child_of_child.html: {% extends 'child.html' %} {% block child_block %} <p>Overriding child</p> {% endblock %} Creating a new block child_block in child.html and having child_of_child.html extending child.html and overriding this block does not work until I also include child_block

Django Paginated Comments .. is there any existing solutions?

◇◆丶佛笑我妖孽 提交于 2019-12-08 06:46:27
问题 is there any existing pagination solution for Django contrib.comments? What I need is just a simple paginated django comments, for the Basic Blog application (from the Django Basic Apps) I used, using a simple has_previous and has_next I have copied the django.contrib.comments and tried modify the code but with no success. The code is pretty hard to understand (django/contrib/comments/templatetags/comments.py) because it consists of Node and Parser here is my comments.html template I used for

Django - ImageField files not showing up?

狂风中的少年 提交于 2019-12-08 06:08:53
问题 This is my models.py: class UserImages(models.Model): user = models.ForeignKey(User) photo = models.ImageField(upload_to=get_file_path) and this is my view which uploads images: def uploadImageView(request): if request.method == 'POST': form = UploadImageForm(request.POST, request.FILES) if form.is_valid(): instance = form.save(commit=False) instance.user = request.user instance.save() return redirect('/') else: form = UploadImageForm() return render(request, 'image.html', {'form': form}) and

How do you place a variable inside a template tag's argument?

谁都会走 提交于 2019-12-08 05:55:17
问题 With Django media I could do the following: {% for language in LANGUAGES %} <script type="text/javascript" src="{{ MEDIA_URL }}app/js/jquery.ui.datepicker.{{ language.0 }}.js"></script> {% endfor %} Now, I'd like to switch to static files. However this (obviously) does not work any more: {% for language in LANGUAGES %} <script type="text/javascript" src="{% static "app/js/jquery.ui.datepicker.{{ language.0 }}.js" %}"></script> {% endfor %} Is there some clean way to achieve what I'm trying to

django checkbox select all

自古美人都是妖i 提交于 2019-12-08 05:43:51
问题 how can i select all checkbox when i click header checkbox? By javascript? How? And can i do that in easier method? thanks:D run.html <form name="form" method="post" action="/home/{{build}}/"> <br> <input type="submit" value="Delete" style="margin-left:149px; width:80px; height:30px"> <input type="hidden" name="build_id" value="{{build_id}}" /> <table border="1"; style="margin-left:150px; border-collapse:collapse;margin-top:10px"; cellpadding="4" borderColor=black> <tr bgcolor=#888888> <td>

Mobile templates based on user-agent in django ensuring thread safety

拜拜、爱过 提交于 2019-12-08 05:27:10
问题 I am developing the mobile version of my website, so thought of using user-agent as the criteria for serving different templates for mobile and web version. I successfully read the user-agent information from nginx and passed it as header to gunicorn server. Then I created a middleware which reads this header and changes the templates directory in settings file. This seemed to work initially but then I realized that there is race condition happening as this method is not thread safe. (I