I get the following error after adding the profile_picture field: This profile_picture field is an “ImageField” set as “Null = True”. I have tried the following: def create_user(…., profile_picture=None, ….). It didn’t work. and the error occurs only in command prompt when i create superuser from there. Here is my models.py Answer Well, you need to create the create_superuser function
Tag: django
Django channels: No module named ‘asgiref.sync’
I am following this guide for channels tutorial (https://media.readthedocs.org/pdf/channels/latest/channels.pdf) and after adding channels to top of INSTALLED APPS, adding ASGI_APPLICATION = ‘mysite.routing.application’ to my setting file and creating following routing.py: I am getting this error after running python manage.py runserver: ModuleNotFoundError: No module named ‘asgiref.sync’ I have following versions of libraries: Can someone help me ? I am new to
Generate PDF from html template and send via Email in Django
I’m trying to generate a pdf file from an HTML template using Weasyprint python package and I need to send it via email using. Here’s what i have tried: But it returns an error as TypeError: expected bytes-like object, not HttpResponse How can I generate and send a pdf file to an email from HTML template? Update: With this updated
Django: Get previous value in clean() method
I have a model CustomModel with an IntegerField. When I create a new instance of CustomModel in the admin, I have to do validation, so I use the clean method and have access to the value with. My problem: When I change the instance of CustomModel, I only have access to the new, changed value but not to the original
django-rest-framwork got AttributeError when attempting to get a value for field
I want to get all prodcut table values with join product_ratings table. I did somthing like this but this code give me AttributeError. So I did product_ratings = ProductRatingSerializer(many=True) in product serializer and used this value in the field, but it’s not working: The full error message: view : its serializer classes: related model class : Answer Default reverse lookup
form for simultaneously editing two django models with foreign key relationship
I am trying to find a simple way to create a form that allows the editing of two models with foreign key relationship simultaneously. After some research, it seems that Inline formsets come very close to what I want to do. The django documentation offers this example: And then, Let’s suppose Author has a second field, city. Can I use
python manage.py migrate: No module named ‘muypicky.base’
Background: I’m taking a beginners Django course and I’ve run into an issue. The following command isn’t working in Terminal. Running on Mac Virtual environment Taking UDEMY Course: try-django-v1-11-python-web-development Command: python manage.py migrate Answer After going through your files, i found that you haven’t imported local.py and production.py in your __init__.py add the following code to __init__.py file inside settings
After login the `rest-auth`, how to return more information?
I use django-rest-auth in my Django project. After login the rest-auth/login/, how to return more information? In the rest-auth/login/, when I login the user, it returns a key. I want to also return the user’s information, how can I get this? Answer At last, I get my solution: In the project settings.py, add the TOKEN_SERIALIZER like bellow: Now I get
Pass argument to Django form
There are several questions on stackoverflow related to this topic but none of them explains whats happening neither provides working solution. I need to pass user’s first name as an argument to Django ModelForm when rendering template with this form. I have some basic form: Here’s my sample class-based view: What do I pass to MyForm when initialising it and
Write Persian in slug and use it in address bar in django
I use django and in my models I want to write Persian in slugfield (by using utf-8 or something else) and use the slug in address of page I write this class for model: But there is nothing in slug column after save and I don’t know what to write in url to show Persian. Can you tell me what