django-templates

JSON on Django template

邮差的信 提交于 2019-12-11 17:13:31
问题 While making a website, I ran into a problem. I am sending a JSON data from views.py to my template to print each attribute value from JSON data, but the data showing is empty. data = { "philip": {"age": 20, "salary": 10000}, "jerry": {"age": 27, "salary": 30000} } names = ["philip", "jerry"] return render(request, 'index.html', {'data': data, 'names': names}) I'm storing the names from JSON data in a list and sending both data and names to template. <div class="col-sm-3"> {% for name in

CSS file is not loaded

懵懂的女人 提交于 2019-12-11 17:10:03
问题 I have a simple Django app and I cannot figure out why my CSS file is not loaded. Any help to nail the problem is appreciated! The error that I am getting is this: GET http://127.0.0.1:8000/static/aztracker/css/mystyle.css net::ERR_ABORTED This is where my css file is sitting: myproject/aztracker/static/aztracker/css/mystyle.css code_search_form.html: {% load staticfiles %} {% load static %} <!DOCTYPE html> <head> <meta charset="utf-8" /> <title>Search Code</title> <!-- CUSTOM STYLES -->

How to split one form fields into multiple fields of a model in django?

痞子三分冷 提交于 2019-12-11 16:59:16
问题 This question is similar to Using multiple input fields for one model's attribute with django and How to render two form fields as one field in Django forms? What I need is basically the opposite of MultiValueField where I can save data from one form field - Name into two model fields - Firstname, Lastname . I'm unable to find any such thing like the opposite of MultiValueField. Can someone please suggest me what is the better way to do it. 回答1: Why don't you define the name field in Form and

Migrating to django 1.11 - “context must be a dict rather than Context.”

北慕城南 提交于 2019-12-11 16:56:21
问题 I started getting this error right after migration to 1.11.15 from 1.10. Here's the view code: def signin(request): form = forms.LoginForm() form_reset = forms.PasswordResetForm() if request.method == "POST": form = forms.LoginForm(request.POST) if form.is_valid(): login(request, form.user) messages.success(request, "You are now signed in") return redirect(reverse('landscape')) d = { 'form': form, 'form_reset': form_reset } return render(request, "signin.html", d) the "return" statement is

Rendering different part of templates according to the request values in Django

谁说胖子不能爱 提交于 2019-12-11 16:55:35
问题 In my view to render my template I receive different parameters through my request. According to these parameters I need to render different "part" in my templates. For example let say that if I receive in my request to_render = ["table", "bar_chart"] I want to render a partial template for table and an other for bar_chart to_render = ["bar_chart", "line_chart"] Then I will want to render a partial template for the bar_chart and an other for line_chart Can I define this in my view? Or do I

how to import data from .csv file to django sqlite using import.py

风格不统一 提交于 2019-12-11 16:55:32
问题 i want to retrieve data from csv file but my hardware(RFID) output gives me two different entries of same employee for timein & timeout WorkNames.csv In this there are double entries i want only one row for one employee in models.py Employee class so please help in my METHOD1 by suggesting some code which can combine 2rows into one while transfering data into sqlite OR by helping in METHOD2 by suggesting some code to import data from output.csv METHOD 1: I used import.py to import data. Data

django - insert a custom option in a select statement that is auto-generated from database table

橙三吉。 提交于 2019-12-11 16:42:21
问题 I have a drop down (select) form that pulls the select options form a database table. The options change almost all the time depending on certain variable. I need to add one more option all the way to the bottom of the drop down that will always be the same. Something that will say "more options". Any ideas? Thanks! 回答1: This is easy enough to do by overriding __init__ on the Form sub-class you're using. It should work equally well on a ModelForm as well. I'm not sure how you're populating

Unable to print the variable passed from view to template

与世无争的帅哥 提交于 2019-12-11 16:38:48
问题 I am trying to pass the variable ,I am obtaining from view to the template but it is showing in the preview of the web-browser(chrome) but not on actual screen. Following is my view file: analyzer=SentimentIntensityAnalyzer() data={} with open('today_5th_oct_new.csv','r',newline='', encoding='utf-8') as f: reader = csv.reader(f) for row in reader: data[row[0]]=float(row[1]) analyzer.lexicon.update(data) def index(request): return render(request, "gui/index.html") @csrf_exempt def output

Django template tags beginner

久未见 提交于 2019-12-11 16:33:39
问题 How can I do this Example.html {% for number in numbers %} {{ number }} ##### 1 {{ Form1 }} ##### first loop {{ number }} ##### 2 {{ Form2 }} ##### second loop {% endfor %} Form1, Form2... have been passed though views 回答1: The easiest place to fix this might be in your view. Zip the numbers and forms together: numbers = [1,2] forms = [Form1, Form2] numbers_and_forms = zip(numbers, forms) Then in your template you loop through them together. {% for number, form in numbers_and_forms %} {{

Jquery Ajax post to update django sessions in views

柔情痞子 提交于 2019-12-11 16:14:47
问题 I am sending the values from my form fields , so as to store them in sessions in django. I am doing the following, but it does not receive the data in POST in django. <script type="text/javascript"> var eventID = $('#id_eventID').val(); var start = $('#id_start').val(); $('a').click(function () { console.log("Inside click"); $.post({ url: "/update_session/", type: "POST", data: {eventID: eventID, start: start}, success: function(response){}, complete: function(){}, error: function (xhr,