浏览代码

Fix submit form with file uploads for anonymous users without a session key (#385)

Co-authored-by: Huub Bouma <huub@pythonunited.com>
Huub Bouma 4 年之前
父节点
当前提交
2a6dfd6486
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      coderedcms/models/page_models.py

+ 4 - 0
coderedcms/models/page_models.py

@@ -1178,6 +1178,10 @@ class CoderedFormMixin(models.Model):
             if type(val) == InMemoryUploadedFile or type(val) == TemporaryUploadedFile:
                 # Save the file and get its URL
 
+                # Custom code to ensure that anonymous users get a session key.
+                if not request.session.session_key:
+                    request.session.create()
+
                 directory = request.session.session_key
                 storage = self.get_storage()
                 Path(storage.path(directory)).mkdir(parents=True,