django-views

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

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

django class based view returns empty string when POST

大兔子大兔子 提交于 2019-12-25 03:49:25
问题 To demostrate: from django.views.generic.base import View from django.views.decorators.csrf import csrf_exempt from django.utils.decorators import method_decorator class TestView(View): @method_decorator(csrf_exempt) def dispatch(self, request, *args, **kwargs): return HttpResponse('haha') urls.py is url(r'^test/', TestView.as_view()), so when GET you can see haha , but when doing POST you get a blank page... What am I missing here? Edit: To clarify what I am doing. I am writing a JSON stream

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

get a multiple choice queryset in Django view and save it

久未见 提交于 2019-12-25 03:12:08
问题 I have a multiple choice field with a foreign key. I want to save which keeper was attending a training session and I want to list all keepers as a multiple choice field. class AddAttendance(forms.ModelForm): attendanceKeeper = Attendance.objects.only("keeper","present").all() keeperValues = Attendance.objects.values_list("keeper__id", flat=True).distinct() keeper = forms.ModelMultipleChoiceField(widget=forms.widgets.CheckboxSelectMultiple, queryset=Keeper.objects.filter(id__in=keeperValues,

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

Get count on several filtered subqueries in template

Deadly 提交于 2019-12-25 02:58:55
问题 I recently asked for how to get count on filetered subqueries in a template and got an answer here: Get count on filtered subqueries in template Now I realised that I need this extended as following (which I think is a lot mroe than my first question, therefor creating a new one here): Show articles that doesn't match the tag, but then with 0 as count. Extend to allow counting on different tags. With the following model: class Category(models.Model): ... class SubCategory(models.Model):

Split Django Queryset in template for Bootstrap Carousel

瘦欲@ 提交于 2019-12-25 02:57:25
问题 I have a model Banner with fields image and name . I need data from this model to be displayed in groups of three on a moving Bootstrap carousel. My current implementation is the most expensive and simple one I could think of. banner1 = Banners.objects.filter(id__exact=1) repeated for 9 entries in the Model. My question is that is it possible to split one queryset Banners.objects.all() into the three groups of three entries and then how would I go about displaying the three groups across

I can't get the values from django dropzone into view

放肆的年华 提交于 2019-12-25 02:34:24
问题 I have trouble getting the django Dropzonejs values of the chosen file into django. It just creates an empty file object in the models. The problem is that I can't get the values into the model. It just creates aa blank model. HTML: <form class="dropzone" action="{% url 'teacher_assignment_add_file' OBJECTID %}" method="POST"> {% csrf_token %} <div class="fallback"> <input name="Assignment-File" type="file" multiple /> </div> </form> <ul class="list-group list-group-activity dropzone-previews

Django post data from Javascript function

狂风中的少年 提交于 2019-12-25 02:27:31
问题 I'm trying to send a string to a post view via checkbox being checked and unchecked. The part I am having trouble with is on the post view being able to get read the data. I have the name being generated during the templating of the HTML to tell me the id of the item. Then the javascript is supposed to pass the name of the checkbox to the post view and then just print out the post value. Error The error I'm getting is that it returned a " None " so I'm thinking I'm not getting the name right.