Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Reorganizing ManyToMany models into a different order
I have an setup similar to this. class Author(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) books = models.ManyToManyField(Book) def __unicode__(self): return self.title class Book(models.Model): title = models.CharField(max_length=100) author = models.ForeignKey(Author) def __unicode__(self): return self.title Now in my admin panel I can select an author and add Books underneath that specific author. When I print out all the books for each author it prints them in the order that they were added in the admin panel. Is it possible to modify the order in the admin panel so that when they print, they print in the order of the admin panel? -
How to make the images same fit or same size?
I'm developing an e-commerce project in django, I have created a model for images and tried to resize or thumbnail the images but it seems this is not working for my case or maybe this is Front-end issue. When the vendor uploads the image products, I want the image products to fit and look in the same line regardless of the image original size. I don't want them to show like in this picture so I want the price and button to be in the same line. I tried to resize the images but won't work -
GeoDjango prevent save latitude and longitude field
i had created longitude and latitude field on my admin, but when i use draw marker instead of input long/lat field, my empty value long/lat field save override my pointfield. Do you have solution for it ? Thank you for reading my question and sorry for my english is bad. model.py class Hostels(models.Model): osm_id = models.CharField(max_length=10) code = models.IntegerField(null=True) fclass = models.CharField(max_length=28) name = models.CharField(max_length=100, default='') address = models.CharField(max_length=100, default='') image_upload = models.ImageField(upload_to='image_nhatro', null=True, blank=True) price = MoneyField(max_digits=14, decimal_places=2, default_currency='VND', default='0') created_at = models.DateField(auto_now_add=True) updated_at = models.DateField(auto_now=True) area = models.FloatField(blank=True, null=True) description = models.TextField(blank=True, null=True) room = models.IntegerField(blank=True, null=True) people = models.IntegerField(blank=True, null=True) phone = models.IntegerField(blank=True, null=True) name_contact = models.CharField(max_length=100, default='') mail = models.CharField(max_length=100, default='') geom = models.PointField(srid=4326, blank=True) def __unicode__(self): return self.name form.py class HostelAdminForm(forms.ModelForm): latitude = forms.FloatField(min_value=-90, max_value=90, required = False) longitude = forms.FloatField(min_value=-180, max_value=180, required = False) class Meta(object): model = Hostels exclude = [] def save(self, commit=True): self.instance.geom = Point(self.cleaned_data["longitude"], self.cleaned_data["latitude"]) return super(HostelAdminForm, self).save(commit) admin.py class quanly_nha_tro(LeafletGeoAdmin): list_display = ('name', 'created_at', 'updated_at') exclude = ('fclass','osm_id','code') form = HostelAdminForm my img admin -
Make Django 3 REST render HTML template
I am trying to build a Django (version 3.05) REST API call that will render to a chosen HTML template. I am, however, receiving a number of errors that I haven't found a solution to on StackOverflow (And yes, I've looked far and wide). Since my errors are many and varying depending on what I attempt, let me rather ask how to do it correctly to begin with. In my view set up (below), what do I need to add (or change) in order to render the queryset to an HTML template? models.py: from django.db import models class Hero(models.Model): name = models.CharField(max_length=60) alias = models.CharField(max_length=60) def __str__(self): return self.name serializers.py: from rest_framework import serializers from .models import Hero class HeroSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Hero fields = ('name', 'alias') views.py: from rest_framework import viewsets from .serializers import HeroSerializer from .models import Hero class HeroViewSet(viewsets.ModelViewSet): queryset = Hero.objects.all().order_by('name') serializer_class = HeroSerializer # over here - how do I render the queryset /to/my/template.html myapi/urls.py: from django.urls import include, path from rest_framework import routers from . import views router = routers.DefaultRouter() router.register(r'heroes', views.HeroViewSet) -
Django error 'model' object is not iterable
Good afternoon, I am following a Django tutorial to lean and I came up with an TypeError at /x/ I am not sure what I am doing wrong here is the model class articulos(models.Model): nombre = models.CharField(max_length=30) seccion = models.CharField(max_length=30) precio = models.IntegerField() here are the views from django.shortcuts import render from django.http import HttpResponse from GestionPedido.models import articulos def buscar(request): if request.GET["prd"]: #mensaje = "Artículo buscado: %r" %request.GET["prd"] producto = request.GET["prd"] articulo = articulos.objects.filter(nombre__icontains = producto) return render(request, "resultadobusqueda.html", {"articulos":articulos, "query":producto}) else: mensaje = "No has introducido nada %r" return HttpResponse(mensaje) and here is the temple <html> <body> <p>Estas buscando: <strong>{{query}}</strong></p> {% if articulos %} <p>Articulos encomtrados {{articulos|length}} articulos</p> <ul> {% for articulo in articulos %} <li> {{articulos.nombre}} </li> {% endfor %} </ul>> {% else %} <p>Articulos no encontrado</p> {% endif %} </body> </html> it does mark the error {% for articulo in articulos %} I had some other errors that I have manage to find but this one is driving me crazy. I am still learning and finding it all very interesting. Thank you very much! -
Does anyone have an idea how can I set up a specific subscription in stripe with such a special requirements for upgrading and downgrading?
I am working on a platform able to analyse data of the users. I would like to use Stripe payments however I have some problems. At first I would like to describe how I would like my pricing look like in order to make it clearer to understand for you what I want to achieve. During account creation the user can select an amount for example from 1$ to 1000$ that will be available for all services. This amount will be charged every month so this will be working as a subscription plan. The difference is that the amount is not used proportionally each day of the month, as is the case of subscriptions. For example, the user starts one month pricing period 5th of the month with amount equals to 10$. During first 10 days of this period he does not execute any actions so he still has 10$. On the 11th day, he starts the service and uses 4$ within 5 hours. From this time he does not use any tools until the end of the current period and he has 6$ left. I decided at the moment that unused funds will probably not be transferred to the … -
Like Button simultaneously working on all instances at the same time when clicked Jquery, Ajax
i am new to Jquery and Django, I have a problem with the like button, I changed all the id's to classes but now when liking one post, all the like buttons on all posts in the list are getting triggered at the sametime. When using ID, only the 1st instance is working. Is there a way to sort out this issue? js. $(document).ready(function(event){ $(document).on('click', '.like-btn', function(event){ event.preventDefault(); var pk = $(this).attr('value'); $.ajax({ type: 'POST', url: pk, data: {'csrfmiddlewaretoken': '{{ csrf_token }}'}, datatype: 'json', success: function(response){ $('.like_snippet').html(response['form']) console.log($('.like_snippet').html(response['form'])); }, error: function(rs, e){ console.log(rs.responseText); }, }); }); }); like snippet.html <form action="{% url 'posts:like_post' post.slug %}" method="post">{% csrf_token %} {% if is_liked %} <button type="submit" id="like" name="post_slug" value="{% url 'posts:like_post' post.slug %}" class="like-btn btn-sm btn-outline-danger">{{ post.likes.count}} Unlike{{ post.likes.count|pluralize }}</button> {% else %} <button type="submit" id="like" name="post_slug" value="{% url 'posts:like_post' post.slug %}" class="like-btn btn-sm btn-outline-info">{{ post.likes.count}} Like{{ post.likes.count|pluralize }}</button> {% endif %} this is the snippet in the homepage and the tag <div id="like-snip" class="like_snippet"> {% include 'posts/like_snippet.html' %} </div> Is there a way to make this work? I tried changing ID's and classes but still it doesn't work. Thanks in advance! -
WYSIWYG with images uploader, how to upload images after writing in the wysiwyg
I'm writing an application where a user can write a diary, also the user can add images, so I'm using the input file to choose images and un put inside the content editable. After the images are in the content editable, I can see the html as img base 64. So, I was thinking if is possible to upload images after the user submitted everything? or should I upload the images via Ajax and put inside the editor with the right url. (I only think that this option people can upload images than delete from the editor and these images will be kept inside the server useless.) Thank you for any response! -
I got an API on AWS how to post json data using django?
It is working fine when I pass data from POSTMAN. I just want to call the API from Django the same as we do in the postman. -
Merge two Different fields result django Query
I have a model from which I want to get data in a same object(JSON) I have this model class Suggestion(models.Model): city = models.CharField(max_length=250 , null=True , blank=True) name = models.CharField(max_length=250 , null=True , blank=True) Now I will query like this name = Suggestion.objects.filter(name__icontains=search) city = Suggestion.objects.filter(city__icontains=search) Name=nameSeilizerr(activities,many=True) serializer=CitySeilizer(city,many=True) In serializer I will send only name in Nameserializer and city in city Serilizer. Main Concept is I want to suggestion to user either its Name or city name in field. Any help would be highly appreciated. -
Django Bootstrap Modal Forms - Open modal inside another modal
How can I open a model inside another modal in Django Bootstrap Modal Forms? I'm following this guide: https://pypi.org/project/django-bootstrap-modal-forms/#description and I was successful in making a simple modal form. However, I would like to add a new option to the choices in the dropdown list if my choice is not in the list. How can I achieve this output? Also, if ever I submit the 2nd modal form, would the dropdown list from the 1st modal form refresh to display the recently added option? -
How can I use a related field in a SlugRelatedField?
I have the following structures class State(models.Model): label = models.CharField(max_length=128) .... class ReviewState(models.Model): state = models.ForeignKey(State, on_delete=models.CASCADE) ... class MySerializer(serializers.HyperlinkedModelSerializer): state = serializers.SlugRelatedField(queryset=ReviewState.objects.all(), slug_field='state__label', required=False) class Meta: model = MyModel fields = [ 'id', 'state', # this points to a ReviewState object .... ] What I'm trying to do is using the State object's label as the field instead. But it doesn't seem like djangorestframework likes the idea of using __ to lookup slug fields. Would it be possible to do this? If it was: class MySerializer(serializers.HyperlinkedModelSerializer): state = serializers.SlugRelatedField(queryset=State.objects.all(), slug_field='label', required=False) that would be no problem, but I'm trying to use the ReviewState instead. -
How to set chats and newsfeed on same page in django
I want a page like facebook's desktop version which has many functionalities on a single page like newsfeed and chats. I am using django framework. I have created separate urls for chat and newsfeed but I don't know how to set all those pages on homepage. I want user to redirect to this page after logging in. Please help I am in early stage of django. -
Best way to render my python game on a webpage via django
So I just finished making a simple guessing game. You have to guess the random number in 22 guesses. I want to be able to eventually study the data from the users input via machine learning. I decided to use the Django framework. How would I go about doing this? I have set everything up already ( I think ). How do I put the .py game on a webpage. How would I style the logic i made? ( as its just text in a console so far) would i have to put the game in some sort of container and then direct that in a view? I am so confused on the best way to do this lol. Any help will be much appreciated and I am sorry if I am coming across as a noob. :) -
Calling a REST API when a django webserver starts
I have a django webserver that has some code to handle data from dialogflow. So for my project I need to have a user and project list that is cached and will be updated only at regular intervals/ at the startup of webserver. For example Everytime the webserver is started I need to make two rest calls and store the resultant data in variables which i can use later. This is to avoid repeatedly doing those calls since that data is fairly static. Is there a way in django to do this? -
Why it is giving 403 forbidden error once I submit the form?
I was following a newsletter app project. I got 403 error.It is storing data but once i click the subscribe button it shows this error.But unless I remove response=sg.send(message) and obisously not sending the mail.But without this line, app will be incomplete. project/letter/views.py def random_digits(): return "%0.12d" % random.randint(0, 999999999999) @csrf_exempt def new(request): if request.method =='POST': sub = Subscriber(email=request.POST['email'], conf_num=random_digits()) sub.save() message = Mail( from_email=settings.FROM_EMAIL, to_emails= sub.email, subject='Newsletter Confirmation', html_content='Thank you for signing up for my email newsletter! \ Please complete the process by \ <a href="{}/confirm/?email={}&conf_num={}"> clicking here to \ confirm your registration</a>.'.format(request.build_absolute_uri('/confirm/'), sub.email, sub.conf_num)) sg = SendGridAPIClient(settings.SENDGRID_API_KEY) response = sg.send(message) return render(request, 'index.html', {'email': sub.email, 'action': 'added', 'form': SubscriberForm()}) else: return render(request, 'index.html', {'form': SubscriberForm()}) project/letter/models.py class Subscriber(models.Model): email = models.EmailField(unique=True) conf_num = models.CharField(max_length=15) confirmed = models.BooleanField(default=False) def __str__(self): return self.email + " (" + ("not " if not self.confirmed else "") + "confirmed)" project/urls.py from django.contrib import admin from django.urls import path from letter import views urlpatterns = [ path('admin/', admin.site.urls), path('new/', views.new, name='new') ] templates/index.html <div class="container"> <div class="col-12"> <h1>Email Newsletter</h1> </div> <div class="col-12"> {% if email %} <p>{{ email }} has been {{ action }}.</p> {% endif %} </div> {% if form %} <div class="col-12 … -
Django, ajax request and JsonResponse
I'm trying to get the data obtanied filling a form utilizing a ajax call. First of all I have created my models.py: class Costi_materiale(models.Model): codice_commessa=models.ForeignKey(Informazioni_Generali, on_delete=models.CASCADE, null=True) numero_lavorazione=models.ForeignKey(Lavorazione, on_delete=models.CASCADE, null=True) The forms.py: class CostiMaterialeForm(forms.ModelForm): class Meta: model = Costi_materiale fields = "__all__" And finally my views.py: class CostiRicavi(ListView): model = Costi_materiale template_name = 'commesse/costiericavi.html' context_object_name = 'costs' def get_context_data(self, **kwargs): context = super(CostiRicavi, self).get_context_data(**kwargs) context.update({ 'form_1': CostiMaterialeForm(), }) return context class Costi_materiale(View): def get(self, request): codice_commessa1 = request.GET.get('codice_commessa', None) numero_lavorazione1 = request.GET.get('numero_lavorazione', None) obj = Costi_materiale.objects.create( codice_commessa = codice_commessa1, numero_lavorazione = numero_lavorazione1, ) info = { 'id':obj.id, 'codice_commessa':obj.codice_commessa, 'numero_lavorazione':obj.numero_lavorazione, } data = {'info': info} return JsonResponse(data) After I have created my template, in which I have put a form (using crispy) and a jquery code, like the following: <form id="addCostoMateriale"> {% csrf_token %} <div class="form-row"> <div class="form-group col-2 0 mb-0" > {{form_1.codice_commessa|as_crispy_field}} </div> ......... $("form#addCostoMateriale").submit(function() { var codice_commessaInput = $('input[name="codice_commessa"]').val().trim(); var numero_lavorazioneInput = $('input[name="numero_lavorazione"]').val().trim(); if (codice_commessaInput && numero_lavorazioneInput) { // Create Ajax Call $.ajax({ url: '{% url "costi_materiale" %}', data: { 'codice_commessa': codice_commessaInput, 'numero_lavorazione': numero_lavorazioneInput, }, dataType: 'json', success: function (data) { if (data.info) { appendToUsrTable(data.info); } } }); } else { alert("All fields must have a valid value."); } … -
Django page freezes after form submission
recently I am facing an issue that on a page where I have 3 forms on a blog post (they all have separate views to handle them) after I want to submit a comment the page freezes and I need to close the page. This happened on both Chrome and Safari. I do not know where the issue is as I see no error on the console, I can see the POST being successful on the terminal and I do not see any errors overall. My javascript that handles the Ajax: $(document).ready(function(){ $('textarea').keyup(function (e) { var rows = $(this).val().split("\n"); $(this).prop('rows', rows.length); }); var s = 0; $("#post-comment-button-viewer").click(function(){ if(s == 0){ $('textarea').val('') $("#post-comment-form-div").fadeIn(); s = -1; } else { $("#post-comment-form-div").fadeOut(); s = 0; } }) $('.inside-post-detail #likeBtn').on("click", function (e) { e.preventDefault(); if($(".inside-post-detail #likeBtn i").hasClass("fa-thumbs-up")){ $(".inside-post-detail #likeBtn i").removeClass("fa-thumbs-up").addClass("fa-thumbs-down"); } else { $(".inside-post-detail #likeBtn i").removeClass("fa-thumbs-down").addClass("fa-thumbs-up"); } }) $('.post-comment-form').on("submit", function (e) { e.preventDefault(); e.stopImmediatePropagation(); $.ajax({ type:'POST', url: $(this).attr('action'), headers: {'X-CSRFToken': '{{ csrf_token }}'}, data: $(this).serialize(), dataType: 'json', success: function(data) { $("#post-linked-comments div").html(data.comments); $('textarea').val(''); $('.reply-btn').on("click", function () { $("#modal-comment-reply textarea").attr("placeholder","Add your reply") $("#modal-comment-reply textarea").addClass("comment-reply-adjust") var c_id = $(this).data('id'); $("#c-get-id").val(c_id); $('textarea').val(''); $("#modal-comment-reply").modal("show"); }); $('.view-replies').on('click', function () { var h = $(this).data('hidden'); var curr = $(this).text() var … -
no reverse match error when trying to call a view function in django
I want to call a view function, Person2, when pressing the persons button but it seems that there is a miss match in the url. I am trying to call my function from a template wtih the id of person. The template displays the result of a search query that comes from the main page, but I want to be able to call a view function when pressing the person button for further information. my template, searchResult.py: {% extends "artdb/index.html" %} {% block sr1 %} <ul> <a class="btn btn-light btn-outline-success my-2 my-sm-0" role="button" href="{% url 'artdb:person2' person.id %}"> Persons: {{person.count}} </a> <a class="btn btn-light btn-outline-success my-2 my-sm-0" role="button" href="{% url 'artdb:search' %}"> Activities: {{activity.count}} </a> <a class="btn btn-light btn-outline-success my-2 my-sm-0" role="button" href="{% url 'artdb:search' %}"> Members: {{member.count}} </a> <a class="btn btn-light btn-outline-success my-2 my-sm-0" role="button" href="{% url 'artdb:search' %}"> Comments: {{comment.count}} </a> <br></br> {% if person.all %} {% for p in person.all %} <h6>First name: {{p.first_name}}</h6> <h6>Last name: {{p.last_name}}</h6> <h6>Phone: {{p.phone_number}}</h6> <h6>Adress: {{p.street_address}}</h6> <h6>Zip Code: {{p.zipcode}}</h6> <h6>City: {{p.city}}</h6> <h6>Country: {{p.country}}</h6> <h6>Payment: {{p.payment}}</h6> {% for c in p.comment.all %} <h6>Comment: {{c}}</h6> {% endfor %} <hr> {% endfor %} {% for d in activity.all %} <h6>Activity name: {{d.activity_name}}</h6> <h6>project name: {{d.project.project_name}}</h6> … -
Unable to create log files in Django using CentOS server
My django project is hosting in centos Server, which is working fine. I've added a new functionality and to check if its working properly, I've added logging to the one file as follows. In my views.py import logging logging.basicConfig(filename='/tmp/logging/testlog.log', level=logging.DEBUG) def myfunction(request): logging.debug('my function started') user = User.objects.all() return render(request, 'myfunction.html', { 'user':user, }) my understanding is that this should create a testlog.log file in /tmp/logging but that is not happening. I specifically chose /tmp/logging folder as it does not require any permissions for creating or writing files, yet my log file is not being created in the server -
ERROR : 'AnonymousUser' object has no attribute '_meta' , when new user is added by extending User Model
I'm trying to add a new user(Using Signup Form) by Extending User Model Using a One-To-One Link. In the signup form I am using 2 forms, userSignup and userSignup_profile. userSignup contains details of user for the fields which are already in 'auth_user' userSignup_profile contains other information like Address, pincode, etc. Please Refer the link which explains what I'm trying to do: https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html#onetoone Models.py class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) phone = models.CharField(max_length=10) address = models.TextField(max_length=200) pincode = models.IntegerField(default=0) @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) @receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): instance.profile.save() Forms.py class userSignup(forms.ModelForm): class Meta: model = User fields = ('first_name', 'last_name','username', 'password', 'email') class userSignup_profile(forms.ModelForm): class Meta: model = Profile fields = ('phone', 'address', 'pincode') user_signup.html <body> <form action="user_signup" method="POST"> {% csrf_token %} {{form.as_p}} {{ profile_form.as_p}} <input id="next" type="hidden" name="next" value=" {{ request.GET.next }} "/> <button class="primary" type="submit" value="login">SIGNUP </button> </form> </body> views.py def user_signup(request): if request.method == "POST": user_form = userSignup(request.POST, instance=request.user) profile_form = userSignup_profile(request.POST, instance=request.user.profile) if user_form.is_valid() and profile_form.is_valid(): user_form.save() profile_form.save() return redirect('/') else: return redirect('user_signup') else: form = userSignup() profile_form = userSignup_profile() return render(request,"user_signup.html",{'form':form, 'profile_form':profile_form}) Error : Request Method: POST Request URL: http://127.0.0.1:8000/user_signup Django Version: 3.0.5 Python Version: 3.7.2 Installed Applications: … -
Convert QuerySet to python list in Django
I have this script: lec_name = request.POST['selected_name'] data = Schedules.objects.filter(name=lec_name) data_list = data.values_list('schedule', flat=True) print(data_list) This gives below OUTPUT: <QuerySet ["[['1', 'Subject 01', 'Hall 01', 'Tuesday'], ['2', 'Subject 02', 'Hall 03', 'Monday']]"]> Then I tried below script to convert data_list to a list: converted_list = list(data_list) This gives below OUTPUT: ["[['1', 'Subject 01', 'Hall 01', 'Tuesday'], ['2', 'Subject 02', 'Hall 03', 'Monday']]"] This works fine. But I'm not getting the expected output properly. EXPECTED OUTPUT: [['1', 'Subject 01', 'Hall 01', 'Tuesday'], ['2', 'Subject 02', 'Hall 03', 'Monday']] How can I solve this? I found a lot of answers about this, but none helped. I'm using Python 3.7.4, Django 3.0.1 -
how to disable submit button until file selected for upload
I am working on one web application in which i am taking pdf file and then extract it, For file input I have used a django form for uploading pdf. I'd like to disable the submit button, until user selects an pdf to upload.I tried jQuery also but failed to get id of FileField. forms.py from django import forms class browse(forms.Form): file = forms.FileField() extractdata.html {% extends "invoicedata/base.html" %} {% block content %} <main role="main" class="container" style="margin-right: 11%;"> <div class="col-md-12"> <h2>Extract From Pdf</h2> <hr> <div class="container"> <div class="row"> <div class="col-12"> <div class="card"> <div class="card-header"> Featured </div> <img class="card-img" src="https://vectorified.com/images/parser-icon-30.png" alt="bgimage"> <div class="card-img-overlay "> <div class="card" style="width:40%; margin-top:50px;" > <div class="card-body" > <form method="POST" class="post-form" enctype="multipart/form-data"> {% csrf_token %} {{ form.as_p }} <input class="btn btn-primary" onclick='start(0)' type="Submit" name="submit" value="Extract & Save"> </form> <br> <h5>EXtracted Data will apear here</h5> <hr> {% for key, value in result.items %} <h6>{{key}} : {{value}}</h6> {% endfor %} </div> </div> </div> </div> </div> </div> </div> </div> </main> {% endblock content %} -
Django - Show a different form depending on a dropdown list
I'm creating an online quiz and I want to be able to add two different types of questions. I created two models and forms according to my two different types of questions. I added my app in INSTALLED_APPS, added a path in urls.py and registered my models in admin.py. I'd like to show the correct form according to what you chose in the dropdown list. This his what I made so far : My two models in models.py : from django.db import models from django.contrib.auth.models import User class Question_Num(models.Model): num_question = models.IntegerField(default=0) question = models.CharField(max_length=200, unique=True) answer = models.IntegerField(default=0) class Meta: verbose_name = 'Question' verbose_name_plural = 'Questions' def __str__(self): return f'Question n°{self.num_question}' class QCM(models.Model): num_question = models.IntegerField(default=0) question = models.CharField(max_length=200, unique=True) choice_1 = models.CharField(max_length=200, unique=True, default='') choice_2 = models.CharField(max_length=200, unique=True, default='') choice_3 = models.CharField(max_length=200, unique=True, default='') choice_4 = models.CharField(max_length=200, unique=True, default='') class Meta: verbose_name = 'QCM' verbose_name_plural = 'QCM' def __str__(self): return f'QCM n°{self.num_question}' Then my two forms in forms.py : from django import forms from django.contrib.auth.models import User from .models import Question_Num, QCM, Point class Form_Creation_Question(forms.ModelForm): num_question = forms.IntegerField(label='Numéro de la question') question = forms.CharField() answer = forms.IntegerField() class Meta: model = Question_Num fields = ['num_question', 'question', 'answer'] class … -
How to insert HTML string into a Microsoft Word document?
I have an HTML string captured through user input in a Web application through TextArea. I would like to populate this HTML string into a Microsoft Word template file. I can populate normal string into the template file. However, with HTML string, I am not sure, how to do it. In terms of technology, I am developing a web application in Django.