django-templates

I need advice on how to implement a checkbox in Django

拟墨画扇 提交于 2019-12-14 02:32:22
问题 I am trying to create a way that a student can enroll to a teacher's course. I added a boolean field to my StudentData model and from there I added a many-to-many field to my Course model. Each of my course page is a generated slug page and there all students are listed. I want that near each student a checkbox will be shown. And if teacher selects more students and presses Enroll button, only those students can view the course. Now, the template conditionals I can do them myself, but I am

Django how to modify database records by template

一个人想着一个人 提交于 2019-12-14 02:15:34
问题 I want to delete the records which i select, and run.html will refresh, how can i do that? Since i use function run in views.py to send records in database, and run need one parameter build which can be got by using run.name , so i think i need to pass "run.name" and "run.id" when i click the submit button. urls.py urlpatterns = patterns('', (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), (r'^home/$', 'views.home'), (r'^home/(?P<build>[^/]+)/$'

Pass {% url %} to custom template tag in Django

喜你入骨 提交于 2019-12-14 01:24:17
问题 I'm developing a custom Django template tag that requires multiple arguments. One of those arguments is a URL. When I try to do this: {% my_tag arg1 {% url "myview" %} arg3=5 %} I get the following template syntax error: Could not parse the remainder: '{%' from '{%' How can I pass a URL to a custom template? 回答1: Simple url tag supports assignment. {% url 'myview' as my_url %} {% my_tag arg1 my_url arg3=5 %} 回答2: In case anyone really does want to get this working without having a lot of junk

Calling a templatetag from a view — CSRF not gtting populated

筅森魡賤 提交于 2019-12-13 21:54:49
问题 I am using inclusion_tags to generate portions of my pages that repeat in many different places across my site. templatetags/tags.py @register.inclusion_tag('chunk_template.html') def output_chunk(object, edit): ... # Lots of set up work here that I don't want to duplicate in the view return { ... } Upon AJAX submit of a form on the page, I need to refresh the very same HTML outputted by output_chunk(). To avoid completely rewriting output_chunk() in a view, I did the following as recommended

compare the date of all DateFields in a model to the current date

瘦欲@ 提交于 2019-12-13 21:12:15
问题 if i have in my model class MyModel(models.model): field1 = models.ForignKey(AnotherModel) field2 = models.DateField(blank=True, null=True) field3 = models.DateField(blank=True, null=True) field4 = models.DateField(blank=True, null=True) field5 = models.DateField(blank=True, null=True) ... field10 = models.DateField(blank=True, null=True) i want to test for each field if the day is in the past, so i can use in my template something like that: {% for field in context.datetime_fields %} {% if

Django Invalid block tag: 'else'

梦想与她 提交于 2019-12-13 20:25:29
问题 Newbie question. I need to extend to the user template if the user is authenticated otherwise extend the guest template. I have the following code at the top my page. {% if request.user.is_authenticated %} {% extends 'users/base.html' %} {% else %} {% extends 'guests/base.html' %} {% endif %} But then I get the following error: TemplateSyntaxError at /events/ Invalid block tag: 'else' If I don't use extends inside the condition then it works. So i'm confuse what is wrong: {% if request.user

printing a list of persons with more than one home, each home with more than one phone number

空扰寡人 提交于 2019-12-13 19:34:16
问题 I have a class Person which can have several Homes, each one with one or many Phone numbers. I have defined the classes, but now i am trying to create a view wich list every person, with all its homes and all the phone numbers for each home address... something like: john smith 123 fake str 305-99-8877 305-99-8876 321 oak road 444-98-7654 peter guy 453 north ave... so far i have something like this: (on my views.py) def ViewAll(request): people = Person.objects.all() render_to_response(

Django templatetags ISO to date

╄→尐↘猪︶ㄣ 提交于 2019-12-13 18:39:56
问题 This question is similar to this one but distinctly different, in my opinion. I have an object that has some datetime attributes. In order to serialize it and store as a JSON string, I call the .isoformat method (using a custom JSON encoder). The other way around, I expected Django template tags to be able to resolve this for me. I have a JSON object that I convert to a dictionary by calling json.loads . The resulting attribute has the value 2015-10-07T14:57:00.501597+00:00 when I simply call

How to export queryset in Django 1.7 to xls file?

守給你的承諾、 提交于 2019-12-13 18:39:56
问题 I using Django 1.7.1 with Python 3.4. I would like to export search results to Excel file. I have this function in view.py def car_list(request): page = request.GET.get('page') search = request.GET.get('search') if search is None: cars= Car.objects.filter(plate__isnull = False ).order_by('-created_date') else: cars= Car.objects.filter(plate__contains = search ).order_by('-created_date') paginator = Paginator(cars, 100) # Show 100 contacts per page try: cars= paginator.page(page) except

django-userena views.py and user registration issues

╄→гoц情女王★ 提交于 2019-12-13 18:06:41
问题 django-userena does not have a views.py file. It uses instead html files, i would like to use this views.py instead of the html files, because i want to add some other features, like a file uploader. I'm having a hard time implementing apps like django-jquery-file-upload The second question is how to activate the user's account automatically after that he confirms his email. 回答1: The first thing that i would like to do is get rid of the html files and replace them with this views.py, django