Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
RuntimeError: populate() isn't reentrant
I got a legacy project based on Django as backend and Angularjs on the front. It's deployed and working, but I got no docs at all so I had to guess everything out of how to deploy it in local, how the system works and that. Now, I've been asked to set it up in a pre-production environment, and so I tried to do, I copied all the configs from the production server and changed as necessary to fit the new environment [Thu Mar 15 07:08:53.612256 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] mod_wsgi (pid=13884): Target WSGI script '/opt/mysite/mysite/wsgi.py' cannot be loaded as Python module. [Thu Mar 15 07:08:53.612336 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] mod_wsgi (pid=13884): Exception occurred processing WSGI script '/opt/mysite/mysite/wsgi.py'. [Thu Mar 15 07:08:53.612539 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] Traceback (most recent call last): [Thu Mar 15 07:08:53.612602 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] File "/opt/mysite/mysite/wsgi.py", line 19, in <module> [Thu Mar 15 07:08:53.612611 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] application = get_wsgi_application() [Thu Mar 15 07:08:53.612624 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] File "/usr/local/lib/python3.6/dist-packages/django/core/wsgi.py", line 12, in get_wsgi_application [Thu Mar 15 07:08:53.612632 2018] [wsgi:error] [pid 13884:tid 140222719059712] [remote 212.170.177.164:49429] django.setup(set_prefix=False) … -
How to create content_type object in DRF?
Generic model - Phone class Phone(Model): number = CharField(max_length=50) content_type = ForeignKey(ContentType, on_delete=CASCADE) object_id = PositiveIntegerField() content_object = GenericForeignKey('content_type', 'object_id') Model - Client class Client(Model): title = CharField(max_length=100) phones = GenericRelation(Phone) Serializer - Client class ClientSerializer(ModelSerializer): title = CharField(required=True) phones = PhoneObjectRelatedField(queryset=Phone.objects.all(), many=True, required=False) Serializer - Phone class PhoneObjectRelatedField(RelatedField): def to_representation(self, obj): data = { 'number': obj.number } return data def to_internal_value(self, data): phone = Phone.objects.create( number=data['number'], object_id=???, content_type_id=5 ) return phone POST-Request body { "title": "John", "phones": [ { "number": "1-123456789" }, { "number": "2-123456789" } ] } Problem The problem is that while creating new Client, I cannot provide current Client's ID for his phones (obviously because current Client is not created yet, so he has no ID yet). As you can see in 'to_internal_value' method, I need both 'content_type_id' and 'object_id' for create new Phone for current Client, and I can provide 'content_type_id' because it's known already for Client class. But I can't provide 'object_id'. What should I do ? -
Hide model from main admin list
In my Django app, I have an Attribute model which has a many-to-many relationship to a MeasurementMethod model. I put an inline for MeasurementMethod in the admin interface for Attribute, but I don't think it is useful to have a separate interface for managing MeasurementMethods at all; there's no reason why a user would say, "Gee, I wonder what Attributes can be measured by water displacement." However, this left no way to create new MeasurementMethods from the inline editor until I found Anton Belonovich's post, which says that I need to admin.model.register(MeasurementMethod) first. I did that, and sure enough the edit and create buttons appeared. But now on the admin page, where there's a list of apps and the models that can be managed, there's an entry for MeasurementMethod that I don't want. Is there a way to get rid of it? Or is there a better way to accomplish this? -
Not able to connect mysql with python 2.7 in django 1.11 getting error while installing mysqlclient and MySQL-python both
i am trying to install mysql client to connect mysql with python 2.7 for django project but getting error, even i tried MySQL-python connector to install but getting error there also. C:\Users\syedabdul\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dve rsion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -Ic:\python27\include -Ic:\pyt hon27\PC /Tc_mysql.c /Fobuild\temp.win32-2.7\Release\_mysql.obj /Zl _mysql.c _mysql.c(29) : fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory error: command 'C:\\Users\\syedabdul\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2 ---------------------------------------- Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\syedab~1\\appdata\\local\\temp\\pip-build-xgy30p\\mysqlc lient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec')) " install --record c:\users\syedab~1\appdata\local\temp\pip-rs9dvc-record\install-record.txt --single-version-externally-managed --compile" fail ed with error code 1 in c:\users\syedab~1\appdata\local\temp\pip-build-xgy30p\mysqlclient\ -
Django with and without Nginx
I am using Django to develop a web application on the linux server. When it comes to deployment, a proposed way is to use Nginx to communicate with the client and Django only need to communicate with Nginx with uwsgi protocol. The relationship is client<-Http->Nginx<-uwsgi->Django server Latter I found that I can also push the server on public network with python manage.py runserver 0:0:0:0 It seems that the Nginx can help serve the static file and media. My question is, what is exactly the benefit of using Nginx as the middleman? -
Something goes wrong when use uwsgi with my django application
Well. It's hard to describe what have happended on me. When I ran my django applicetion with commands python manage.py runserver it was ok to authenticate and login in. But When I ran it with uwsgi. I got a mistake which said FieldDoesNotExist: The fields "set(['area_id'])" do not exist on the document "User".However,I am sure I have defined that filed in my document. And here is my debug page on chrome I use python2.7 and django1.8.6 and the database is mongodb -
What is the way to create the Quiz Experience for the appearing candidate for Django Quiz app
For a QUIZ Django project, we have, an almost ready back-end for creating questions and answers. Now , I want to know, how will we organize this quiz? Some points regarding this: Start the quiz which will go throw N diff questions . So does the student login or just enter some basic info like email and name, and just starts by , lets say some button "Start Quiz". A timer also should be shown indicating remaining time. What if different questions need different timers . Like difficult questions 2 mins, but easy ones only 1 min. User should not be able to reset this timer by any means (resubmit page or restart quiz). There needs to be a result page to show Summary . Should this "Result" be a model? (I think yes). How do we ensure , user cannot retake the exam ? I started with this idea , but I can't get past the timer thing. How do we implement this? Ideas: Should we use Django sessions? How?. Or this should be done using Javascript?. Should the client tell the server, if the time is almost over or the back-end server should send a signal . -
How to retrieve data from an existing db file and display it on webpage using Django?
This is the views.py file: from django.shortcuts import render from django.views.generic import TemplateView from .models import Report import random Create your views here. class HomePageView(TemplateView): def get(self, request, **kwargs): args = {} data = Report.objects.all() args['data'] = data return render(request, 'index.html',args) -
Prevent user to access my website's service more than once without signup
I am building a web app with Python, Django and I want certain service available on my website to be accessed only once by a user/client if he/she is not a registered user. How can I identify whether the same user/client has accessed the system before without registering and if yes the access to the service must be blocked. I have tried using the IP address of the user's system but person with a different network on the same machine can still access the service which I don't want. Any kind of help will be very helpful for me. -
Read and process multiple json files in python
I'm trying to process many json files with user input. If there are three indentical data ["a","a","a"] in GeneListA, I suppose it is going to run the code three times with jsonurl = "http://abc.def/a/format=json" However, I got the error : Traceback (most recent call last): File "/Users/me/miniconda3/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner response = get_response(request) File "/Users/me/miniconda3/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response response = self.process_exception_by_middleware(e, request) File "/Users/me/miniconda3/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/Users/me/Desktop/Project/gsea/analysis/views.py", line 49, in result for gene in data[0][gidA]: KeyError: 'NC_000913\r\nNC_000913\r\nNC_000913' And here is my code: AGOAnnos = [] for genefromlist in GeneListA: jsonurl = "http://abc.def/"+genefromlist+"/format=json" print(jsonurl) with urllib.request.urlopen(jsonurl) as url: data = json.loads(url.read().decode()) for gene in data[0][gidA]: for anno in data[0][gidA][gene]: if type(anno) is dict: GOAnno = re.search(r'GO:\d+',anno["ID"]) if GOAnno: AGOAnnos.append(GOAnno.group()) elif type(anno) is str: GOAnno = re.search(r'GO:\d+',anno) if GOAnno: AGOAnnos.append(GOAnno.group()) -
Accessing an image in an httpresponse
I have a django test method that is supposed to test that the correct image was returned in an httpresponse. Here is the code for the test: c = Client() originalFilePath = '../static_cdn/test.jpg' image_data = open(originalFilePath, "rb") with open(originalFilePath, "rb") as fp: response = c.post('/', {'image': fp}) self.assertEqual(image_data,response) The test isn't working because I'm comparing the opened image with the entire http response instead of just the image it has. I've tried to access the image by checking for fields it may have but it doesn't appear to have any. In the view I'm returning the image using HttpResponse(image_data, content_type="image/jpg") and from looking at the fields from the class in the docs I'm not seeing a field that would return the image. How can I access the image from the httpresponse so that it can be tested? -
Different Size Options in Django and Swift
I'm working on an app that will allow users to select different sizes on their products that will be related to a Django server. Right now the model that I'm using is: SIZE = ( ('Sizes',( ('small', 'Small'), ('medium', 'Medium'), ('large', 'Large'), ('XL', 'Extral Large'), ('xxl', 'Extra Extra Large'), )), ) sizes = MultiSelectField(choices=SIZE, max_choices=32, max_length=32) price = models.DecimalField(decimal_places=2, max_digits=4) What I want to do is have restaurant put in the the price at each individual size but, I'm not sure the best way to do this. How would I convert the form to combine Size and price? Also, since I'm going to be pull this into my API, how would I populate this dictionary into my app? -
Error: could not determine PostgreSQL version from '10.3' - Django on Heroku
I tried to push from local env to Heroku master. No new requirements from the previous commit. However, I received an Error which saying the system could not determine PostgreSQL version from "10.3". Here is my requirements list: amqp==1.4.9 anyjson==0.3.3 appdirs==1.4.3 awscli==1.11.89 billiard==3.3.0.23 boto==2.46.1 botocore==1.5.52 celery==3.1.25 Collectfast==0.5.2 colorama==0.3.7 dj-database-url==0.4.2 Django==1.11.1 django-celery==3.2.1 django-recaptcha==1.3.0 django-redis-cache==1.7.1 django-storages==1.5.2 django-storages-redux==1.3.2 docutils==0.13.1 gunicorn==19.7.0 honcho==0.5.0 jmespath==0.9.2 kombu==3.0.37 olefile==0.44 packaging==16.8 Pillow==4.3.0 psycopg2==2.6.2 pyasn1==0.2.3 pyparsing==2.2.0 python-dateutil==2.6.0 pytz==2018.3 PyYAML==3.12 redis==2.10.5 reportlab==3.4.0 rsa==3.4.2 s3transfer==0.1.10 selenium==3.4.0 six==1.10.0 vine==1.1.4 virtualenv==15.1.0 virtualenvwrapper-win==1.2.1 whitenoise==3.3.0 and below is the error in the build log. Collecting amqp==1.4.9 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 1)) Downloading amqp-1.4.9-py2.py3-none-any.whl (51kB) Collecting anyjson==0.3.3 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 2)) Downloading anyjson-0.3.3.tar.gz Collecting appdirs==1.4.3 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 3)) Downloading appdirs-1.4.3-py2.py3-none-any.whl Collecting awscli==1.11.89 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 4)) Downloading awscli-1.11.89-py2.py3-none-any.whl (1.2MB) Collecting billiard==3.3.0.23 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 5)) Downloading billiard-3.3.0.23.tar.gz (151kB) Collecting boto==2.46.1 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 6)) Downloading boto-2.46.1-py2.py3-none-any.whl (1.4MB) Collecting botocore==1.5.52 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 7)) Downloading botocore-1.5.52-py2.py3-none-any.whl (3.5MB) Collecting celery==3.1.25 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 8)) Downloading celery-3.1.25-py2.py3-none-any.whl (526kB) Collecting Collectfast==0.5.2 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 9)) Downloading Collectfast-0.5.2-py3-none-any.whl Collecting colorama==0.3.7 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 10)) Downloading colorama-0.3.7-py2.py3-none-any.whl Collecting dj-database-url==0.4.2 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 11)) Downloading dj_database_url-0.4.2-py2.py3-none-any.whl Collecting Django==1.11.1 (from -r /tmp/build_28bcf3a327daae7657433628289c1501/requirements.txt (line 12)) … -
manually update django model instance in put request. django django rest framework
The way I am doing my put request by exposing the parent model and then searching through the room_set becasue I need to see if the user has permissions to mess with the parent models related objects. now with that away, I am trying to do a manual put. This put will act more like a patch but the CORS policy doesn't like it when I use PATCH in my local. so I put. So Im a little confused about what to do next. How do I add the new value to my object or ignore the attribute on my model if I don't have any data on it in the request? Here is the model and the put request. class Room(models.Model): venue = models.ForeignKey(Venue, on_delete=models.CASCADE) name = models.CharField(max_length=100, null=True, blank=True) online = models.BooleanField(default=False) description = models.CharField(max_length=1000, blank=True, null=True) privateroom = models.BooleanField(default=False) semiprivateroom = models.BooleanField(default=False) seatedcapacity = models.CharField(max_length=10, null=True, blank=True) standingcapacity = models.CharField(max_length=10, null=True, blank=True) minimumspend = models.PositiveSmallIntegerField(blank=True, null=True) surroundsoundamenity = models.BooleanField(default=False) outdoorseatingamenity = models.BooleanField(default=False) stageamenity = models.BooleanField(default=False) televisionamenity = models.BooleanField(default=False) screenprojectoramenity = models.BooleanField(default=False) naturallightamenity = models.BooleanField(default=False) wifiamenity = models.BooleanField(default=False) wheelchairaccessibleamenity = models.BooleanField(default=False) cocktailseatingseatingoption = models.BooleanField(default=False) classroomseatingoption = models.BooleanField(default=False) ushapeseatingoption = models.BooleanField(default=False) sixtyroundseatingoption = models.BooleanField(default=False) boardroomseatingoption = models.BooleanField(default=False) theaterseatingoption = … -
python- Django local server refuses to connect to admin page
AttributeError at /admin/ 'WSGIRequest' object has no attribute 'user' Request Method: GET Request URL: http://127.0.0.1:8000/admin/ Django Version: 2.0.3 Exception Type: AttributeError Exception Value: 'WSGIRequest' object has no attribute 'user' Exception Location: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/contrib/admin/sites.py in has_permission, line 186 Python Executable: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5 Python Version: 3.5.2 Python Path: ['/Users/zeinalabidin/Desktop/website', '/Users/zeinalabidin/Desktop/website', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python35.zip', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages'] Server time: Thu, 15 Mar 2018 03:13:25 +0000 I am running the latest version of django and everything is setup correctly. When I try to run the local django server it runs fine. but when I try to access the admin page it shows the error above. I have looked for other solutions online but non of them seem to fix my problem. can anyone help? -
How do I create a demo account in Django?
I have visited a couple of sites and they offer the option to try their site without registering, but you can login with something like someusername@somesite.com and somesiteguest. I want to implement this for my own site. Currently I am using django-allauth for handling registration and logins. I am just not sure how to handle users login with the same credentials. -
attempting to delete an object in many to one relation but will not delete django. Django rest framework
I am deleting a model in a many to one relation. Youll notice in the delete method I am exposing the parent model. This is for permissions which I will write later. The code is not deleting the objects. As in method runs and my javascript removes the object. But If I reload the page, I get the objects back. what could be happening? def delete(self, request, *args, **kwargs): venuepk = kwargs.get('venuepk', None) venue = get_object_or_404(Venue, pk=venuepk) venuerooms = venue.room_set.all() roompk = kwargs.get('roompk') roomobject = None for room in venuerooms: if room.pk == roompk: roomobject = Room.objects.get(pk=roompk) roomobject.delete() return Response({}) return Response(status.HTTP_404_NOT_FOUND) -
An alternative query to postgres' distinct in Django
Given this django model: def Price(model.Model): date = models.DateTimeField() item = models.ForeignKey('Item', on_delete=models.CASCADE) price = models.IntegerField(blank=True, null=True) The goal is to get the most recent price for each item which can be queried quite simply.. assuming the orm is using postgresql: Price.objects.all().order_by('date').distinct('item') When using other database engines, it isn't possible to distinct on specific fields, and I'd like to avoid locking myself into postgres so I've been looking for a query that emulates it. I've written/found a query that does the job: Price.objects.raw(''' SELECT P1.* FROM `merchapi_pricelog` P1 LEFT JOIN `merchapi_pricelog` P2 ON P1.item_id = P2.item_id AND P1.date < P2.date WHERE P2.date is NULL ''') The raw query is faster than loading and filtering the data in code but I am interested to see if there is a better way to do this in a db-agnostic way that doesn't resort to using raw sql. -
Django- Testing file returned in httpresponse
I have a django test method that checks to see if an image returned as an httpresponse equals the image as it was opened before the http request was sent to the view: def test_uploaded_file(self): c = Client() originalFilePath = '../static_cdn/test_img.jpg' image_data = open(originalFilePath, "rb") with open(originalFilePath, "rb") as fp: response = c.post('/', {'image': fp}) self.assertEqual(image_data,response) For some reason, the test is returning this error: AssertionError: <open file u'../static_cdn/test_img.jpg', mode 'rb' at 0x7fed326b6a50> != <HttpResponse status_code=200, "image/jpg"> I think the issue has to do with the fact that the image returned from the view is an httpresponse and while the other image being opened in the test method is not. Why could this test be failing? -
Django user sign up crashes with `TypeError: 'field_name' is an invalid keyword argument for this function`
I would like to add an additional information to user profile during registration. I've created class Profile and defined Django signals: class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) public_email = models.EmailField(null=True, blank=True) extra = models.CharField(max_length=100, default='') def create_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) def save_user_profile(sender, instance, **kwargs): instance.profile.save() post_save.connect(create_user_profile, sender=User) post_save.connect(save_user_profile, sender=User) During the registration form processing I call User.objects.create_user(username=username, password=password, email=email, extra='Extra info') and get TypeError: 'extra' is an invalid keyword argument for this function I've seen a lot of tutorials use this method, moreover Django documentation recommends this method. But I do not understand why it crashes for me. -
objects not deleting from database. Django, Django Rest Framework
I have the following models: class Venue(models.Model): name = models.CharField(max_length=100) description = models.CharField(max_length=1000, null=True, blank=True) streetaddress1 = models.CharField(max_length=150) streetaddress2 = models.CharField(max_length=150 ,null=True, blank=True) approved = models.BooleanField(default=False) declined = models.BooleanField(default=False) eventplannerstaff = models.BooleanField(default=False) declineddate = models.DateField(null=True, blank=True) declineddatestring = models.CharField(max_length=50, blank=True, null=True) declinereason = models.CharField(max_length=200, blank=True, null=True) class Room(models.Model): venue = models.ForeignKey(Venue, on_delete=models.CASCADE) name = models.CharField(max_length=100, null=True, blank=True) online = models.BooleanField(default=False) description = models.CharField(max_length=1000, blank=True, null=True) privateroom = models.BooleanField(default=False) semiprivateroom = models.BooleanField(default=False) seatedcapacity = models.CharField(max_length=10, null=True, blank=True) standingcapacity = models.CharField(max_length=10, null=True, blank=True) I have a REST endpoint with a delete method. I am trying to delete a room. A room is tied to a venue. I am not deleting the room directly as I want to expose the venue in this method. The permission code isn't written yet, but I will be wanting to see if the user has the permissions to mess around with the venues room. The delete method is working but it is not actually deleting the rooms from the database. What am I doing wrong? def delete(self, request, *args, **kwargs): venuepk = kwargs.get('venuepk', None) venue = get_object_or_404(Venue, pk=venuepk) venuerooms = venue.room_set.all() roompk = kwargs.get('roompk') roomobject = None for room in venuerooms: if room.pk == roompk: roomobject = … -
how can i test my custom model manager in django
following is my custom manager class DefaultModelManager(models.Manager): def get_or_none(self, **kwargs): try: return self.get(**kwargs) except self.model.DoesNotExist: return None Model class TestModel(models.Model): objects=DefaultModelManager() how can i test this code? Following is my code class ModelManagerTest(TestCase): def test_can_get_or_none(self): TestModel.create('...') test = TestModel.objects.get_or_none('...') test2 = TestModel.objects.get('...') self.assertEqual(test, test2) def test_cant_get_or_none(self): test = TestModel.objects.get_or_none('...') self.assertEqual(test, None) is it correct??? or another method... What is the best way to test custom model manager -
How to get filename of image in httpresponse
I have a file django view that takes a form request with an image as the submitted content and then returns an httpresponse of the image to be displayed back in the template. I'm new to testing in django and I'm trying to essentially assert that the file that was originally uploaded in the form request is the same one that is being returned back to the user. Here is the code in the view that handles the http request and returns the response: form = PhotoUploaderForm(request.POST or None, request.FILES or None) if request.method == "POST": print request.POST if form.is_valid(): print request instance = form.save(commit=False) instance.save() instance = PhotoUploader.objects.get(id=instance.id) image_full_path = instance.image.path image_data = open(image_full_path, "rb").read() return HttpResponse(image_data, content_type="image/png") In my test function , I have the following code: c = Client() originalFileName = 'Keep-Calm-and-Carry-On.jpg' with open('../../static_cdn/Keep-Calm-and-Carry-On.jpg', "rb") as fp: response = c.post('/', {'image': fp}) self.assertEqual(originalFileName,response.image.path) In order to test whether the original file uploaded is coming back in the response, I'm trying to check that the original filename and the one in the response match. I'm not sure how to get the file name from the response since it is just an image though. How can I get the … -
How to connect canvas with django model
I am having trouble with getting canvas insert to django model field. I'm using forms to get informations from user to create new object and one of them is FileField, which in this case will be canvas. Here's the most important canvas.js var png = ReImg.fromCanvas(document.getElementById('canvas')).toPng(); views.py: form.instance.comics = request.POST("png") create.html: `<form method="post" enctype="multipart/form-data"> {% csrf_token %} {{ form.as_p }} <button id = "png" name = "png" >Save</button> </form>` Is it possible to do something like that? I've looked everywhere for answers, but without result. Form is working, everything is insert to object, but not FileField (canvas in this case). -
How does 'max_length' affect Django models?
Does max_length affect anything outside of the maximum number of characters you can add to a specific database field (i.e. does it affect the amount of memory that is set aside for the database?). Would there be any unintended consequences for setting all fields to the maximum CharField length, which is ~65,000, even if it was completely unnecessary (apart from being bad practice)?