Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
How to translate a polygon in GeoDjango
I have a Place model which has a polygon field: from django.contrib.gis.db import models class Place(models.Model): area = models.PolygonField() I want to translate the area field of an instance of this Place model. Here is how I am doing it right now: from django.contrib.gis.db.models.functions import Translate place = Place.objects.get(pk=1) place.area = Place.objects.filter(pk=place.pk).annotate(new_area=Translate('area', 0.001, 0.001)).first().new_area place.save() This seems very hacky. I think that there should be a way of doing this in the following way: place = Place.objects.get(pk=1) place.area = Translate(place.area, 0.001, 0.001) place.save() But this throws an exception. Should I be using some library? Which one works well with GeoDjango and its models/fields? What is the better way of doing it? -
The get in self.request.Get.get() returning more than one object
This is image of view and i m getting the error get() returned more than one BoothDetails -- it returned 2! . Please can anyone tell me what to do, and filter do not work in self.request.GET.get() The error i m getting -
Access folder inside MEDIA_ROOT
def OverwriteStorage(instance,filename): filename = 'product.csv' fullname = os.path.join(settings.MEDIA_ROOT, filename) if os.path.exists(fullname): os.remove(fullname) return filename static folder structure def OverwriteStorage(instance,filename): filename = 'product.csv' fullname = os.path.join(settings.MEDIA_ROOT, filename) if os.path.exists(fullname): os.remove(fullname) return "product/{filename}".format(filename=filename) This code adds new file. 1st block of code overrides the existing file but it's not under product folder. 2nd block of code doesn't overrides the existing file, but is under the product folder. How should I put the file under product folder overriding the existing file? Thanks. -
Displaying the Sum of Values from All of Its Dependent Models in Foreignkey Dropdown
I have the following two models: class Model_AccountName(models.Model): account_name = models.CharField(max_length = 100, null = True, blank = False) def __unicode__(self): return "Account name: {}, total current quantity: {}".format(self.account_name, ...) # How to include the sum of all of its "quantity" from "Model_Transaction" here class Model_Transaction(models.Model): account_name = models.ForeignKey(Model_AccountName) quantity = models.FloatField(null = True, blank = True) def __unicode__(self): return self.account_name When selecting the foreign-key dropdown from the Model_Transaction model, how can we not only display the "account_name", but also show the sum of all of its related "quantity"? So for example in the dropdown, the selection would look like this: Account name: ABC, total quantity: 213 ... Account name: XYZ, total quantity: 91 I welcome any kind of suggestion/solution. Thank you -
Django ORM to retrieve month name from date time
I need to retrieve month name with sum total price of the corresponding month. Here is my order table sample My try is: month_wise_sales = Order.objects\ .annotate(month=TruncMonth('created_at'))\ .values('month')\ .annotate(total_sales=Sum('total_price')) It will return <QuerySet [{'month': datetime.datetime(2018, 7, 1, 0, 0, tzinfo=<DstTzInfo 'Asia/Dhaka' +06+6:00:00 STD>), 'total_sales': Decimal('138400.00')}, {'month': datetime.datetime(2018, 9, 1, 0, 0, tzinfo=<DstTzInfo 'Asia/Dhaka' +06+6:00:00 STD>), 'total_sales': Decimal('1150.00')}]> My desire is something like this [{'month': July, 'total_sales': Decimal('138400.00')}, {'month': September, 'total_sales': Decimal('1150.00')}] How to resolve this? -
django admin create and change page fields
I am new to django. I have the following classes: class Profile(models.Model): """User profile model, specifying the user's general preferences and language""" GENDERS = ( ('male', _('Male')), ('female', _('Female')), ) POSITIONS = ( ('a', _('A')), ('b', _('B')), ) gender = models.CharField(_("gender"), max_length=10, choices=GENDERS) # We use full_name instead of the default 'first_name' and 'last_name', to enable non-personal users full_name = models.CharField(_("full name"), max_length=60) # A valid two-letter language code which is used when the user is logged in language = models.CharField(_("language"), max_length=2, choices=settings.LANGUAGES, blank=True) . . . . . . class MyUser(AbstractUser): """ The customized user model for the project It has one-to-one relations to Profile and Plan models. """ profile = models.OneToOneField(Profile, null=True, on_delete=models.PROTECT) plan = models.OneToOneField(Plan, null=True, on_delete=models.PROTECT) def get_full_name(self): """ Gets the full name of the user. :return: The user profile's full name if the user has a profile, an empty string otherwise """ return self.profile.full_name if self.profile is not None else "" and in register form, I have user = get_user_model().objects.create_user( form.cleaned_data.get('email'), form.cleaned_data.get('email'), form.cleaned_data.get('password') ) meaning that user's username is his email, and there is no username field in registration form. As you could see there is no firstname and lastname separately and I have one … -
templateUrl is not working with angular and Django
I've been having trouble for like 2 weeks now trying to get my app to display the proper HTML when the url is visiting but it just won't work. I am following this tutorial https://thinkster.io/django-angularjs-tutorial I'm really not sure as to what the problem is, all my JS files are being loaded thinkster-routes.js: (function () { 'use strict'; angular .module('thinkster.routes', []) .config(config); config.$inject = ['$routeProvider']; /** * @name config * @desc Define valid application routes */ function config($routeProvider) { $routeProvider.when('/register', { controller: 'RegisterController', controllerAs: 'vm', templateUrl: '/static/templates/authentication/register.html' }).otherwise('/'); } })(); register.html (what should be displayed) <div class="row"> <div class="col-md-4 col-md-offset-4"> <h1>Register</h1> <div class="well"> <form role="form" ng-submit="vm.register()"> <div class="form-group"> <label for="register__email">Email</label> <input type="email" class="form-control" id="register__email" ng-model="vm.email" placeholder="ex. john@notgoogle.com" /> </div> <div class="form-group"> <label for="register__username">Username</label> <input type="text" class="form-control" id="register__username" ng-model="vm.username" placeholder="ex. john" /> </div> <div class="form-group"> <label for="register__password">Password</label> <input type="password" class="form-control" id="register__password" ng-model="vm.password" placeholder="ex. thisisnotgoogleplus" /> </div> <div class="form-group"> <button type="submit" class="btn btn-primary">Submit</button> </div> </form> </div> </div> </div> index.html: <!DOCTYPE html> <html > <head> <title>TixBlast</title> <base href="/" /> {% include 'stylesheets.html' %} </head> <body> {% include 'navbar.html' %} <div class="container-fluid"> <div class="row"> <div class="col-xs-12 ng-view"></div> </div> </div> {% include 'javascripts.html' %} </body> </html> views.py from django.shortcuts import render from rest_framework import permissions, … -
Add input-tags to an article and create new tag records if it's non-existence in database
I have Tag and Article data models of many-to-many relationships, class Tag(models.Model): owner = models.ForeignKey(User,on_delete=models.CASCADE) name = models.CharField(max_length=100) def __str__(self): return self.name class Meta: ordering = ("id",) class Article(models.Model): tags = models.ManyToManyField(Tag, blank=True) owner = models.ForeignKey(User, on_delete=models.CASCADE) ... When receiving tags inputed from the form, I firstly check if the tags existing to determine whether or not to create new one in database, and then append all input-tags to article. #save the new article in database if article_form.is_valid(): article = article_form.save(commit=False) article.owner = self.request.user article.save() 1, create tags which not found in records #compare tags input_tags = self.request.POST["tags"] input_tags = tags.split(",") query_tags = Tag.objects.all() #get name list of tab objects query_tags = [tag.name for tag in query_tags] #create new tabs in TabTable for tag in input_tags: if tag not in query_tags: Tag.objects.create(name=tag, owner=self.request.user) 2, retrieve input tag objects tag_objs = [] for input_tag in input_tags: try: qualified_tab = Tab.object.filter(name=input_tag)[0] tag_objs.append(qualified_tab) 3, append tags to article article.tags.add(*tag_objs) This is a routine task,but the solution is cumbersome. How to complete such a task elegantly? -
django ORM return top 10 match in manytomany relationship
My models.py has a manytomany relationship between User and Tag class Tag(models.Model): name = models.CharField(unique=True, max_length=32) class User(AbstractBaseUser, PermissionsMixin): tags = models.ManyToManyField(Tag, blank=True) How can I get top 10 tags ordered by the number of users with the tag? Something like Tag.objects.order_by('user_set__count')[10] This command doesn't work and django complains that django.core.exceptions.FieldError: Cannot resolve keyword 'myuser_set' into field. Choices are: id, myuser, name This is puzzling because t1.user_set.count() works where t1 is a Tag instance. Also, is there a better way to get the top 10 without order all data? -
User not associated with post model
I am trying to get the current logged in user to be the author of the the post they create from the Post model. So far all of the information they fill out in the form gets collected and successfully stored in the database except for the user. At the moment it shows that there's no user logged in and I'm not sure why that is. I've tried putting the request.user and instance=request.user for the POST and GET requests and so far nothing seems to work. views.py def create(request): form = PostForm(request.POST or None, request.FILES or None) if form.is_valid(): instance = form.save(commit=False) instance.user = request.user instance.save() return render(request, 'classifieds/latest-ads.html') else: form = PostForm(instance=request.user) args = {'form': form} return render(request, 'classifieds/create-post.html', args) models.py from django.db import models from django.contrib.auth.models import User # Create your models here. class Post(models.Model): title = models.CharField(max_length=150) price = models.CharField(max_length=100) body = models.TextField() contact_email = models.CharField(max_length=80, null=True) contact_number = models.IntegerField(default=250, null=True) pub_date = models.DateTimeField(null=True) author = models.ForeignKey(User, null=True) category = models.CharField(max_length=150, null=True) picture = models.ImageField(upload_to='ad_pictures', default='') def __str__(self): return self.title forms.py from django import forms from .models import Post from django.contrib.auth.models import User class PostForm(forms.ModelForm): class Meta: model = Post fields = ( 'price', 'title', 'body', 'author', … -
Django QuerySet filter on MySQL doesn't show properly
I working on mysql (5.6.38) and django 2.0.2 in my server. And I found this fault result: >>> Tag.objects.filter(created__year=2018) <QuerySet [<Tag: Tricks>, <Tag: Directory>, <Tag: Beginner>, <Tag: API>, <Tag: DRF>, <Tag: Flask>, <Tag: Solution>, <Tag: SSO>, <Tag: Multi Databases>, <Tag: Ajax>, <Tag: Internationalization>, <Tag: Multi Languages>, <Tag: Looping>, <Tag: Security>, <Tag: Internet>, <Tag: Templates>, <Tag: Problem>, <Tag: Database>, <Tag: Settings>, <Tag: Module>, '...(remaining elements truncated)...']> >>> >>> t = Tag.objects.first() >>> t.created.year 2018 >>> t.created.month 7 >>> >>> sum([True for t in Tag.objects.filter(created__year=2018) if t.created.month == 7]) 27 >>> >>> # Why this queryset doesn't work? >>> Tag.objects.filter(created__year=2018, created__month=7) <QuerySet []> >>> >>> # This queryset also >>> Tag.objects.filter(created__year=2018).filter(created__month=7) <QuerySet []> >>> However, this queryset is working fine when I try on local mode. -
Saving the ModelForm containing ForeignKey field referenced to another Model.
Below are my Models class Seminar(models.Model): seminarID = models.AutoField(primary_key=True) presenter_name = models.CharField(max_length=200) location_name = models.TextField() seminar_DT = models.DateTimeField(default=datetime.datetime.now) capacity = models.IntegerField(default=50) class Registration(models.Model): registration_ID = models.AutoField(primary_key=True) seminar=models.ForeignKey(Seminar,to_field='seminarID',on_delete=models.CASCADE) attendee_name = models.CharField(max_length=200,null=True) email_address = models.EmailField() email_sent = models.BooleanField(default=False) Here is the ModelForm I have created for Registration Model class RegistrationForm(forms.ModelForm): class Meta: model = Registration widgets = { "registration_ID": forms.NumberInput(attrs={'required': "required"}), "seminar": forms.SelectMultiple(attrs={'required': "required"}), "attendee_name": forms.TextInput(attrs={'required': "required"}), "email_address": forms.TextInput(attrs={'required': "required"}), "email_sent": forms.NullBooleanSelect(attrs={'required': "required"}), } fields = ('seminar','attendee_name','email_address','email_sent') When I run the above RegistrationForm on my Template I get following window Image of the Registration ModelForm seminar field which is defined as ForeignKey in Registration Model and refers to seminarID in Seminar Model. seminar appears in the registration form pre-populated which is fine but it shows as a Seminar object (2), Seminar object (3)... Also seminarID in Seminar Model is AutoField and Primarykey as well. When I save RegistrationForm my postgresql database doesn't get updated with the new values and selected Seminar object (*). Please advise Both seminar table and registration table snaps are given below seminar table registration table -
Retrieve form.errors from views and print to the console
I want to print the error if the form is valid form = TagForm(request.POST) if form.is_valid(): return HttpResponseRedirect('/index/') else: print(form) However,it throw messages less useful, <tr><th><label for="id_name">Name:</label></th><td><ul class="errorlist"><li>This field is required.</li></ul><input type="text" name="name" maxlength="50" required id="id_name" /></td></tr> I am aware of the error message could be displayed on template {% if form.errors %} {% for field in form %} {% for error in field.errors %} ... {% endfor %} {% endfor %} {% for error in form.non_field_errors %} .... {% endfor %} {% endif %} How could retrieve them from views.py and print to console? -
How to open a new Pop up form while submitting a form ?
I have tried so many times and probably this is a really simple thing but I don't know how to do this. Basically, I have a pop-up form which is a ModelForm and built in Jquery. When something is changed in the form and user Saves the form I need to open another dialog box which does have a list of reason why User changed the form. So, I need to invoke a form in a POST request and again save that data to a table. I tried calling the method which invokes form but the first pop up gets closed as soon as I click Save. -
Drag & Drop Elements in a ListView -Django
I'm looking for a way to drag and drop elements in a ListView template within Django, is this possible? To be more specific, I'm looking for a logged in user (NOT superuser) who has access to only their own content to be able to move their entries around and it saves to the database in that order so the next time they log in it's still in the new order. If drag and drop isn't possible, some other ideas I have are up/down arrows or a box to manually edit the order number and save it that way. Any help in figuring this out or pointing me in the right direction would be much appreciated! I'm pretty new to Python/Django, so if I didn't give enough info on what I need, let me know and I'll try to explain better! Thanks. -
Django deploying on MySQL gives #1071 error "Specified key was too long"
I have been trying this problem for a very long time. But I just cannot seem to find the solution. I am trying to deploy my project on pythonanywhere, where I have chosen MySQL. Whenever I try to migrate my models with python manage.py migrate. I get the following error: This is my models. models.py from django.db import models from django.contrib.auth.models import User # Create your models here. class Thing(models.Model): thing_name = models.CharField(max_length=64, unique=True) def __str__(self): return self.hobby_name class Person(models.Model): user = models.OneToOneField( User, on_delete=models.CASCADE, ) first_name = models.CharField(max_length=64, null=True, blank=False) last_name = models.CharField(max_length=64, null=True, blank=False) hobbies = models.ManyToManyField(Hobby, blank=False) email = models.EmailField(max_length=64, blank=True, null=True, unique=True) city = models.CharField(max_length=64, null=True, blank=False) zip_code = models.CharField(max_length=10, null=True, blank=False) description = models.TextField(max_length=2048, null=True, blank=True) gender = models.CharField(max_length=1, choices=( ('N', 'No answer'), ('M', 'Male'), ('F', 'Female'), ('O', 'Other') ), null=True, blank=True, default="N" ) bad = models.BooleanField(default=False) good = models.BooleanField(default=True) maximum_hours = models.PositiveIntegerField(default=2) def __str__(self): try: string = self.first_name + " " + self.last_name except: string = "name_error" return string Last note is that I have DROPPED and re-CREATED the database several times. Each time by: CREATE DATABASE database_name DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; I am deploying all of this to Pythonanywhere. The … -
django form rendering out of order
I'm learning how to use ModelForms and I've successfully gotten the form to render, but the fields aren't showing up in the order that I'd like them to. I tried changing the order in forms.py and that had no effect. How can I go about changing the order; for instance, putting title at the top instead of the bottom and making the picture field second to last instead of second? forms.py from django.db import models from django.contrib.auth.models import User # Create your models here. class Post(models.Model): title = models.CharField(max_length=150) price = models.CharField(max_length=100) body = models.TextField() pub_date = models.DateTimeField(null=True) author = models.ForeignKey(User, null=True) category = models.CharField(max_length=150, null=True) picture = models.ImageField(upload_to='ad_pictures', default='') def __str__(self): return self.title views.py def create(request): form = PostForm(request.POST or None, request.FILES or None) if form.is_valid(): instance = form.save(commit=False) instance.save() return render(request, 'classifieds/latest-ads.html') else: form = PostForm() args = {'form': form} return render(request, 'classifieds/create-post.html', args) create.html {% extends 'base.html' %} {% block head %} <!-- {% load static %} <link rel="stylesheet" href="{% static 'accounts/login.css' %}" type="text/css"> --> <title>Create Post</title> {% endblock %} {% block body %} <div class="container"><br> <form method="POST" action='' enctype="multipart/form-data"> {% csrf_token %} {{ form.as_p }} <button type="submit" value="submit">Submit</button> </form> </div> {% endblock %} I'd like to … -
Extend inner class attributes in python
In my django application there are several apps which I activated AppConfig via apps.py files and i have one BaseAppConfig class: class BaseAppConfig(AppConfig): launchpad = None def __init__(self, app_name, app_module): AppConfig.__init__(self, app_name, app_module) self.launchpad = self.Launchpad() class Launchpad: show = True icon = "fa fa-cogs" i use this BaseAppConfig in my custom apps like: class CustomerConfig(BaseAppConfig): name = 'customer' class Launchpad: icon = "fa fa-book" and when i try to reach show attribute of CustomerConfig using customer_config.launchpad.show it returns AttributeError. Python overrides all the inner class like new. How can i achieve just extending the attributes of inner class ? -
Google API Sign Out - gapi is not defined - (Django)
I'm having trouble using Google's sign-out function. I keep getting this TypeError: Uncaught TypeError: Cannot read property 'getAuthInstance' of undefined at signOut Here is my code from my footer scripts: <script src="https://apis.google.com/js/platform.js"></script> <script src="{% static 'js/login.js' %}"></script> and the code in my login.js file: function signOut() { var auth2 = gapi.auth2.getAuthInstance(); auth2.signOut().then(function () { console.log('User signed out.'); }); } My sign-in doesn't use gapi like some examples I see, it's more so like the Google guides code: <div class="g-signin2" data-onsuccess="onSignIn"></div> login.js: function onSignIn(googleUser) { var profile = googleUser.getBasicProfile(); var id_token = googleUser.getAuthResponse().id_token; var username = profile.getName(); var email = profile.getEmail(); var avatar = profile.getImageUrl(); // My Login Process Code Here } How am I suppose to get access to gapi? -
Django: how to differenciate if the user is signing in from social_auth or local Django user
Hi I am using Django "social-auth-app-django" package. I have two questions. How to differentiate if the current user is from social media or local Django registered How do we know that the current user is signed-in from which social media platform such as Google, FB or Twitter? -
Wagtail: Dynamically Choosing Template With a Default
I'm wondering if there is a way in Wagtail to enter a custom template path via CharField in a base model, and then establish a template in an inherited model that would be the default. For example: base/models.py class WebPage(Page): template_path = models.CharField() def get_template(self, request): if self.template_path: template = template_path else: template = *something* app/models.py class MyWebPage(WebPage): template = 'default_template.html' Ideally, I'd establish the template attribute in the MyWebPage model, and that would act as a default. However, the get_template method in the WebPage base model would supersede it, but only if it's not empty. Is any of this possible? -
Django: Custom user model, makemigrations fail
I'm trying to create a custom profile for my users, and I'll have different type of users, as well - ie Doctors and Patients. Now, my models are: from django.db import models from django.contrib.auth.models import AbstractUser from django.db.models.signals import post_save from django.dispatch import receiver from django.core.validators import RegexValidator class State(models.Model): name = models.CharField(max_length=100, blank=False) code = models.CharField(max_length=5, blank=False) zip_code = models.IntegerField(blank=False) class City(models.Model): state = models.ForeignKey(State, on_delete=models.CASCADE) name = models.CharField(max_length=100, blank=False) class User(AbstractUser): USER_TYPE_CHOICES = ( ('patient', 'Patient'), ('doctor', 'Doctor') ) user_type = models.CharField( max_length=20, choices=USER_TYPE_CHOICES, default='patient', ) username = None email = models.EmailField('email address', unique=True) USERNAME_FIELD = 'email' REQUIRED_FIELDS = [] class Patient(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) first_name = models.CharField(max_length=30, blank=False) last_name = models.CharField(max_length=30, blank=False) USERNAME_FIELD = 'email' phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be in the following format: '+999999999'.") phone_number = models.CharField(validators=[phone_regex], max_length=17, blank=True) address = models.CharField(max_length=300, blank=False) city = models.ForeignKey(City, on_delete=models.CASCADE) """ class Doctor(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) bio = models.TextField(max_length=500, blank=True) location = models.CharField(max_length=30, blank=True) birth_date = models.DateField(null=True, blank=True) """ Now, the exact error is: python3 manage.py showmigrations admin [ ] 0001_initial [ ] 0002_logentry_remove_auto_add auth [X] 0001_initial [X] 0002_alter_permission_name_max_length [X] 0003_alter_user_email_max_length [X] 0004_alter_user_username_opts [X] 0005_alter_user_last_login_null [X] 0006_require_contenttypes_0002 [X] 0007_alter_validators_add_error_messages [X] 0008_alter_user_username_max_length [X] 0009_alter_user_last_name_max_length contenttypes [X] … -
Update form input with django form value
I am trying to pass legacy db entries to django form. I created the model by using django inspectdb method. Similar to: class Form(models.Model): date_entered = models.DateField(blank=True, null=True) date_needed = models.DateField(blank=True, null=True) client = models.CharField(max_length=50, blank=True, null=True) project_no = models.CharField(max_length=50, blank=True, null=True) map_no = models.CharField(max_length=10, blank=True, null=True) contact = models.CharField(max_length=50, blank=True, null=True) I have create the corresponding view in views.py. def post_edit(request, pk): post = get_object_or_404(Form, pk=pk) if request.method == "POST": form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.published_date = timezone.now() post.save() return redirect('post_detail', pk=post.pk) else: form = PostForm(instance=post) return render(request, 'blog/post_edit.html', {'form': form}) In my post_edit.html. <input type="text" class="form-control" name="client" value= '{{ form.client.value }}' required/> <input type="text" name="projectno" class="form-control" value= '{{ form.project_no.value }}' required/> .. <input type="text" name="jobcontact" class="form-control" value='{{ form.contact.value }}' required/> Client and project_no work (produce values on the form) while contact does not. I have verified the name in model and also the existance of a value for this in the db table. Should I pass something else for these input values. I am new to django. Help please. -
Issue with Django : "NoReverseMatch at /myapp/accueil"
I searched a bit through the web but nobody seemed to get the same issue as me, mine seems to be "too simple", but I can't find the mistake. I use the latest version of Django, with windows. I started a project named "tesutooo", with a single app named "myapp". At the root of the project, I have a dir named "templates/" that I use for as a basis for the others. I have my templates in "myapp/templates/myapp/" So my issue is between "tesutooo/templates/base.html" and "tesutoo/myapp/templates/myapp/accueil.html" Here is my code : tesutoo/tesutoo/urls.py from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site. path('myapp/', include('myapp.urls')), ] tesutoo/myapp/urls.py from django.urls import path from . import views urlpatterns = [ path('accueil', views.accueil), path('date', views.date), ] tesutoo/myapp/views.py from django.http import HttpResponse from django.shortcuts import render from datetime import datetime def accueil(request): return render(request, 'myapp/accueil.html') def date(request): return render(request, 'myapp/date.html', {'date': datetime.now()}) tesutoo/templates/base.html <!DOCTYPE html> <html lang="fr"> <head> <meta charset="utf-8"/> <link rel="stylesheet" href="base.css" /> <title>{% block title %}Mon projet Django ou je fais un peu c'que j'veux mdr{% endblock %}</title> </head> <body> <header>Mon projet qui déchire sa cera</header> <nav id="nav_gen"> {% block nav %} <ul> <a href="{% url 'myapp.views.accueil' %}">Accueil</a> </ul> … -
django SummernoteInplaceWidget - Images Not Working
I am currently testing with the django SummernoteInplaceWidget, and when I try to copy an image into the editor it does not work with the SummernoteInplaceWidget. It works perfectly fine with the SummernoteWidget. I am using the most recent version of summernote-lite from summernote website with the following libraries... <link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote-lite.css" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote-lite.js"></script> Here is my summernote_config in settings.py SUMMERNOTE_CONFIG = { 'summernote': { 'toolbar': [ ['undo', ['undo',]], ['redo', ['redo',]], ['style', ['bold', 'italic', 'underline',]], ['font', ['strikethrough',]], ['fontsize', ['fontsize']], ['color', ['color']], ['para', ['ul', 'ol', 'paragraph']], ], 'width': 760, 'height': 300, 'focus': True, 'fontSizes': ['8', '9', '10', '11', '12', '14', '18', '22','24', '36', '48' , '64', '82', '150'], }, } Here is my code: widgets = { 'summary': SummernoteWidget(), } And the end result after I copy the image... But when I change the widget to SummernoteInplaceWidget... widgets = { 'summary': SummernoteInplaceWidget(), } And try to copy image into the editor, I just get a blank screen, no image is copied. As shown below: Is this expected behavior? I tried changing the iFrame setting to False in settings.py but that did not seem to make a difference. Thanks in advance for any thoughts.