templates

Django html template getting data from nested dictionary

Django html template getting data from nested dictionary Question: I’m having a problem with an html template not displaying model fields sent from a view in a context dictionary called content. This dictionary holds a nested dictionary like: content = {‘indredients’: {recipe id1: QuerySet 1, recipe id2: QuerySet 2, … } } In model.py: class …

Total answers: 2

How to parse text and extract values of parameters in Python

How to parse text and extract values of parameters in Python Question: I have text file like this (it actually has 10000+ lines): Generate placement Place object 4 at (24,21) Place object 21 at (89, 4) Generate movement At time 10, move object 4 to (3,65) with speed 10 At time 54, move object 21 …

Total answers: 1

how to add custom templates in django-ckeditor in django

how to add custom templates in django-ckeditor in django Question: I am trying to use the Templates feature of the CKEditor in Django and I want to add some custom templates in the list. I’ve used this approach. I’ve tried editing myvenvLibsite-packagesckeditorstaticckeditorckeditorpluginstemplatestemplatesdefault.js default.js CKEDITOR.addTemplates("default",{imagesPath:CKEDITOR.getUrl(CKEDITOR.plugins.getPath("templates")+"templates/images/"),templates:[{title:"Welcome Template",image:"template2.gif",description:"A template that you can send to clients as a welcome …

Total answers: 2

Store formatted strings, pass in values later?

Store formatted strings, pass in values later? Question: I have a dictionary with a lot of strings. Is it possible to store a formatted string with placeholders and pass in a actual values later? I’m thinking of something like this: d = { "message": f"Hi There, {0}" } print(d["message"].format("Dave")) The above code obviously doesn’t work …

Total answers: 3

How do I fix Django TemplateDoesNotExist at /?

How do I fix Django TemplateDoesNotExist at /? Question: I reinstall windows on my computer, after I install Python 3.8.3 and Django 3.0.7, anaconda, visual studio code, and a lot of shit. When I continue with my project, I follow my tutorial made some changes and after running the server I found with this error. …

Total answers: 3

Django 2.1 – can't link my models variables in html file

Django 2.1 – can't link my models variables in html file Question: I’m having some problems to design my templates files in Django 2.1 at the index.html of my app I can get in at the details page although when I want to design my detail page in the html file I put the references …

Total answers: 2

Automatically get name of the column with for loop in django template

Automatically get name of the column with for loop in django template Question: I would like to automatically retrieve the name of the column with a for loop. If I know the name of the columns I can write the template in this way: <ul> {% for co in team %} <li>{{ co.name }}</li> <li>{{ …

Total answers: 1

Django template – get object's choice field text

Django template – get object's choice field text Question: This is my model: class Person(models.Model): … DOP = 1 PPP = 2 contract_choices = ( (DOP, ‘always’), (PPP, ‘sometimes’), ) contract = models.CharField(max_length=3, choices = contract_choices) … I need contract field value in my template: {% for person in persons %} {{ person.get_contract_display }} {% …

Total answers: 2

Javascript file not found using relative path during Flask render_template

Javascript file not found using relative path during Flask render_template Question: I’m using Python and Flask to build a simple interaction web app. Testing on localhost:5000 using Chrome. I have one template and one associated javascript file located at: ./templates/main.html ./templates/main_scripts.js The main.html template includes the scripts file like this: <script src=”main_scripts.js”></script> When I render …

Total answers: 1

image is not showing in django template

image is not showing in django template Question: I am facing problem showing image file in the django ecommerce project.Can anyone help in this issue? home.html {% for product in products %} <div class=’col-sm-4′> <div class=”thumbnail”> {% if product.productimage_set.all %} {% for item in product.productimage_set.all %} <img class=’img-responsive’ src=”{{ MEDIA_URL }}{{ item.image}}” /> {% endfor …

Total answers: 1