django

Django form upload request.files empty

笑着哭i 提交于 2021-02-18 12:18:05
问题 I havent posted a question here before, read mostly. Im learning Django and got file upload working before . But now i've broke it somehow. request.FILES is empty when im uploading but i can see the filename in request.raw_post_data. here is the code for the html <form enctype="multipart/form-data" method="post" action="">{% csrf_token %} {{ form.as_p }} <input type="submit" name="submit" value="Upload Photo" /> </form the form class PhotoUploadForm(forms.Form): title = forms.CharField(max

django python collation error

两盒软妹~` 提交于 2021-02-18 12:08:47
问题 What is the reason for the following error? when i try to filter with: if MyObject.objects.filter(location = aDictionary['address']): where location is defined as: location = models.CharField(max_length=100, blank=True, default='') I get the following error when aDictionary['address'] contains a string with a non-alphanumeric character (for example Kīhei): File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaul terrorhandler raise errorclass, errorvalue _mysql

Django cascade delete and post_delete signal

℡╲_俬逩灬. 提交于 2021-02-18 11:55:08
问题 In my application post_delete signals being recorded in a specific model and when it was removed. class A(models.Model): ... class B(models.Model): a = models.ForeignKey('A') class C(models.Model): b = models.ForeignKey('B') def log_delete(sender, instance, **kwargs): logging post_delete.connect(log_delete, sender = A) post_delete.connect(log_delete, sender = C) When you delete an instance of A cascade delete occurs removing B and C instances. How can I disable signal for child instances on

Django开发个人博客入门学习经验贴

房东的猫 提交于 2021-02-18 11:51:33
【写在前面】   入门学习搭建个人博客系统首先还是参考大佬们的经验,记得刚入手Django的时候,一篇博客大佬说过一句话,做技术的不要一开始就扎头于细节中,先把握整体框架,了解这个对象之后再去了解细节,进行优化,深入的学习,所以开始学习搭建个人博客系统的时候还是先从简单入门的开始,这个帖子不是教程贴,是一个经验贴,主要是分享一下学习搭建博客的过程中找到的几个很适合入门的博客,写的真的很详细。PS:网络上的相关教程太多太杂,这几个也只是我在入门的时候觉得几个比较好的,还有很多完整的帖子,没太多时间就没有一一列举出来。 【正文部分】 文章一: Django实例 —— 搭建一个博客(超详细) ♦   备注:这个博主就出了这一篇教程,但是很详细,从头到尾都进行了详细的说明,可以做了入门教程, 了解 一下搭建博客大概是什么流程。 级别:一颗星 (假设上面的菱形是个星) 文章二: django实战(一)简单博客显示 和 django实战(二)一个较完整的博客系统 ♦♦   备注:这个博主出了四篇教程,但是前面的一和二是一个系列的,比较完整的教程。第一个是了解整个搭建的流程,第二个是进行优化,写的很详细。 级别:两颗星 文章三: django项目开发实战——博客 ♦♦♦♦   备注:这个博主出了三篇教程,三篇都是一个系列的,是一个完整的教程。不过对于第一篇,可能博主也是刚上手

Django makemigrations works, migrate fails with “django.db.utils.IntegrityError: NOT NULL constraint failed”

[亡魂溺海] 提交于 2021-02-18 11:29:09
问题 I'm stuck. Django 1.7, SQLite3. I've changed my model to add the thumbnail column, as in this tutorial. It was this: from django.db import models class Article(models.Model): title = models.CharField(max_length=200) body = models.TextField() pub_date = models.DateTimeField('date published') likes = models.IntegerField(default=0) def __str__(self): return self.title and is now this: from django.db import models from time import time def get_upload_file_name(instance, filename): return

Django modelformset_factory delete modelforms marked for deletion

你离开我真会死。 提交于 2021-02-18 11:21:22
问题 When using modelformset_factory how do you delete objects from the database that get marked for delete in the form? I create my modelformset_factory like this: ItemFormset = modelformset_factory(Item, ItemModelForm, extra=1, can_delete=True) qset = Item.objects.filter(pr=pr) formset = ItemFormset(queryset=qset) When the formset comes back in the POST I get the data like so: if request.method == "POST": formset = ItemFormset(request.POST,queryset=qset) if formset.is_valid(): marked_for_delete

How to upload folder on Google Cloud Storage using Python API

痞子三分冷 提交于 2021-02-18 11:20:11
问题 I have successfully uploaded single text file on Google Cloud Storage . But when i try to upload whole folder , It gives permission denied error. filename = "d:/foldername" #here test1 is the folder. Error: Traceback (most recent call last): File "test1.py", line 142, in <module> upload() File "test1.py", line 106, in upload media = MediaFileUpload(filename, chunksize=CHUNKSIZE, resumable=True) File "D:\jatin\Project\GAE_django\GCS_test\oauth2client\util.py", line 132, in positional_wrapper

Auto Populate Slug field django

久未见 提交于 2021-02-18 11:10:14
问题 I have a model defined and over 100+ entries of data in my DB. I would like to auto populate a slug field and see it show up in the admin, since adding new entries for 100+ fields is not something I would like to do. AutoSlug() field doesnt seem to be working when I add it to my model and make the migrations, prepopulated_fields = {'slug': ('brand_name',)} does not work using it within my admin.py and as well I have tried to add the default field on the slug as my desired field name within

Auto Populate Slug field django

删除回忆录丶 提交于 2021-02-18 11:05:39
问题 I have a model defined and over 100+ entries of data in my DB. I would like to auto populate a slug field and see it show up in the admin, since adding new entries for 100+ fields is not something I would like to do. AutoSlug() field doesnt seem to be working when I add it to my model and make the migrations, prepopulated_fields = {'slug': ('brand_name',)} does not work using it within my admin.py and as well I have tried to add the default field on the slug as my desired field name within

Auto Populate Slug field django

感情迁移 提交于 2021-02-18 11:03:59
问题 I have a model defined and over 100+ entries of data in my DB. I would like to auto populate a slug field and see it show up in the admin, since adding new entries for 100+ fields is not something I would like to do. AutoSlug() field doesnt seem to be working when I add it to my model and make the migrations, prepopulated_fields = {'slug': ('brand_name',)} does not work using it within my admin.py and as well I have tried to add the default field on the slug as my desired field name within