django-templates

getting django Url template tag to return something useful:throws reverse error

只谈情不闲聊 提交于 2019-12-25 06:08:15
问题 trying to use the Django {%url %} template tag and keep failing. the view is defined in sitename/transfers/views.py (where transfers is the django app name): def description_ListView(requesst,**kwargs): template_name = 'transfers/description.html' o = get_list_or_404(Transfer, description =kwargs['description']) #print ('o:',o) context_object_name = "transfer_name_list" return render_to_response(template_name,{context_object_name:o,'description':kwargs['description']}) (yes, I DO know that

Pass and View Dictionary from view to template in django

强颜欢笑 提交于 2019-12-25 04:53:24
问题 I am passing the dictionary to the view but it is now showing on the page. i also have print the dictionary on the before passing, and it prints the whole dictionary on the screen perfectly. but when i pass it to the html page, it does not show at all.. view.py def show_log_messages(request): context = RequestContext(request) log_dictionary = {} count = 0 e = log_messages.objects.filter(log_status='Queue').values('sent_to', 'unique_arguments') count = 0 logs = {} for d in e: count +=1 new

No POST response when using checkbox form in my Django template

荒凉一梦 提交于 2019-12-25 04:38:05
问题 Hey there, I am trying to delete Events as chosen by a by a user using check boxes to check of which events they want to be deleted. But for some reason whenever I call request.POST.get('event_list') Nothing is received even though boxes are checked and I end up with nothing. Here is my template and the view that should be deleting the chosen events. {% if event_list %} {% for event in event_list%} {%csrf_token%} <input type="checkbox" name="event_list" id="event{{ forloop.counter }}" />

Django - how to create and use context processors / the variables which the context processors return

白昼怎懂夜的黑 提交于 2019-12-25 04:26:24
问题 Along with my settings.py and urls.py file, I created a context_processors.py file in the same directory. This is my context_processors.py file: from django.contrib.auth.forms import AuthenticationForm def loginFormCustom(request): form = AuthenticationForm() return {'loginForm': form,} and this is my views.py: from django.template import RequestContext from tp.context_processors import loginFormCustom def main_page(request): variables = { 'title': 'This is the title of the page' } return

Why is this template filter invalid?

放肆的年华 提交于 2019-12-25 04:09:33
问题 What am I doing wrong here? I have roundnumber in a module called accounts_extras.py located in the templatetags directory. In my template I have {% load accounts_extras %} at the top. It's also worth noting that 'upto' is currently working in another template (haven't tried it on this template yet), but the issue is with roundnumber. {{ staravg.stars__avg|roundnumber }} is giving me an invalid filter error. #accounts_extras.py from django import template from django.template.defaultfilters

Templates Django (Does not exist at/)

Deadly 提交于 2019-12-25 03:34:31
问题 I'm trying to use the Django templates but i cant even display a simple html line i don't understand why... I searched to resolve it but after many test, the problem remains. This is my structure: My urls.py (which work i tried it with another fonction in views.py): from django.conf.urls import patterns,include, url from django.contrib import admin urlpatterns = patterns('polls.views', url(r'^$', 'home', name = 'home'), url(r'^admin/', include(admin.site.urls)), ) My views.py: from django

Creating dynamic dropdown options based off dropdown selection - stuck

女生的网名这么多〃 提交于 2019-12-25 03:13:01
问题 So I am trying to create a dynamic form where the 2nd dropdown box is populated based on the first dropdown. I am using ajax & jquery to help build this dynamic form in my django project, and I need a bit of help. I have got the ajax call to work properly, and I have sent my choices back to the form, but now I am having trouble populating the form with my choices. Can someone help me make the json output turn into html options? Here is my ajax.py: def switch_plan(request, *args, **kwargs):

Django REST Framework: rendering form elements in list response

寵の児 提交于 2019-12-25 03:12:32
问题 How can Django REST Framework be used to render a list of model instances with specific fields editable by the user? I'm a few months into Django, and only a couple days into DRF. I've tried several different approaches, but just can't seem to wrap my head around it. Prior to using DRF, my workflow would have been to set up a view (and associated URL) that: queried my model, picked my custom form from forms.py (exposing only the fields I needed), put the two together into a dictionary, and

Math comparison operating in Django templates

耗尽温柔 提交于 2019-12-25 03:04:10
问题 i want to compare do simple math in django template like {% forloop.counter > 5 %} {% endfor %} how do i achieve this? 回答1: You can do that with the if tag in Django 1.2 {% for blip in blah %} {% if forloop.counter > 5 %} {# Do somthing #} {% endif %} {% endfor %} If you are still using an earlier version of Django then you can check out the smart if tag on djangosnippets: http://djangosnippets.org/snippets/1350/ 来源: https://stackoverflow.com/questions/3148350/math-comparison-operating-in

Trouble downloading file using Django FileTransfers

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 03:01:15
问题 I have am uploading a file through the admin section of my site that I would like to be able to be publicly downloaded through my website. I know that the file I have uploaded has been successfully uploaded because I can view it in the App Engine Blob storage. I am having trouble finding out what isn't working with the code below: relevant part of my modeL: class CalendarEvent (models.Model): file = models.FileField(upload_to='uploads/%Y/%m/%d/%H/%M/%S/') in my views.py file the relevant code