- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
使用 Django。我有以下模型:
class Postagem(models.Model):
id = models.AutoField(primary_key=True, editable=False)
descricao = models.CharField(max_length=50)
area = models.ForeignKey('core.Area', null=True)
user = models.ForeignKey('User')
categoria = models.CharField(max_length=50, null=True)
post = models.FileField(upload_to='posts/', null=True)
thumbnail = models.FileField(upload_to='posts/', null=True)
def __str__(self):
return self.descricao
以下形式:
class PostForm(forms.ModelForm):
categoria = forms.ChoiceField(choices=[("Video","Vídeo"),("Audio","Aúdio"),("Imagem","Imagem"),("Musica","Música")], required=True)
thumbnail = forms.FileField(required=False)
class Meta:
model = Postagem
fields = ['descricao', 'area', 'user', 'post']
查看:
def profileView(request):
context = getUserContext(request)
if request.method == 'POST':
exception=None
userDict = {}
userDict["user"] = context["user"].id
if "categoria" in request.POST:
newPost = request.POST.copy()
newPost.update(userDict)
form = PostForm(newPost,request.FILES)
print("postform POST: ",newPost, " File ",request.FILES)
if form.is_valid():
print("valid")
try:
form.save()
print("saved")
return HttpResponseRedirect(reverse_lazy('accounts:profile'))
except IntegrityError as e:
print("Integrity Error")
exception=e
else:
print("PostForm error")
print(form.errors)
form.non_field_errors=form.errors
if exception is not None:
form.non_field_errors.update(exception)
context['form']=form
posts = Postagem.objects.get_queryset().order_by('id')
paginator = Paginator(posts, 12)
page = request.GET.get('page')
context["areas"] = Area.objects.all()
try:
posts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
posts = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
posts = paginator.page(paginator.num_pages)
context["posts"]=posts
return render(
request,
'accounts/profile.html',
context
)
最后是模板:
{% for post in posts %}
{% if forloop.counter0|divisibleby:4 or forloop.counter0 == 0 %}
<div id="grid-profile" class="row grid">
<div class="col-md-1"></div>
{% endif %}
{% ifnotequal post.categoria "Imagem"%}
<iframe id=post{{forloop.counter}} width="420" height="315"
src={{post.post.url}}>
</iframe>
{% else %}
<div class="col-md-2">
<button type="button" id="modal1trigger" data-toggle="modal" data-target="#modal1"><img class="img-responsive" src={{post.post.url}}></img></button>
</div>
{% endifnotequal %}
{% if forloop.counter|divisibleby:4 or forloop.counter == posts|length %}
<div class="col-md-1"></div>
</div>
{% endif %}
{% endfor %}
<div class="pagination">
<span class="step-links">
{% if posts.has_previous %}
<a href="?page={{ posts.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ posts.number }} of {{ posts.paginator.num_pages }}.
</span>
{% if posts.has_next %}
<a href="?page={{ posts.next_page_number }}">next</a>
{% endif %}
</span>
</div>
我剪了一些模板...不管怎样,我希望能够添加各种帖子。歌曲、视频、图像、文档等。它正在运行。帖子正在添加中。但是,我有一个反复出现的错误,我不知道为什么。那可能非常危险,所以我开始研究它,但没有找到可接受的答案。 错误仅在尝试获取歌曲或视频时发生。
[21/Sep/2017 23:32:44] "GET /media/posts/13567830_1641362072853439_1924036772_n.mp4 HTTP/1.1" 200 1171456
Traceback (most recent call last):
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 180, in finish
_response
self.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 279, in write
self._write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 775, in write
self._sock.sendall(b)
ConnectionResetError: [WinError 10054] Foi forçado o cancelamento de uma conexão existente pelo host remoto
[21/Sep/2017 23:32:44] "GET /media/posts/13567830_1641362072853439_1924036772_n.mp4 HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53113)
Traceback (most recent call last):
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 180, in finish
_response
self.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 279, in write
self._write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 775, in write
self._sock.sendall(b)
ConnectionResetError: [WinError 10054] Foi forçado o cancelamento de uma conexão existente pelo host remoto
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "C:\Users\eduardo\Envs\ProExC\lib\site-packages\django\core\servers\basehttp.py", line 88, in handle_erro
r
super(ServerHandler, self).handle_error()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 368, in handle
_error
self.finish_response()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 180, in finish
_response
self.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 331, in send_h
eaders
if not self.origin_server or self.client_is_modern():
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 344, in client
_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 639, in process_re
quest_thread
self.finish_request(request, client_address)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 361, in finish_req
uest
self.RequestHandlerClass(request, client_address, self)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 696, in __init__
self.handle()
File "C:\Users\eduardo\Envs\ProExC\lib\site-packages\django\core\servers\basehttp.py", line 155, in handle
handler.run(self.server.get_app())
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 144, in run
self.close()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\simple_server.py", line 35, in cl
ose
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
----------------------------------------
[21/Sep/2017 23:32:44] "GET /media/posts/03_-_The_Mute.mp3 HTTP/1.1" 200 1179648
Traceback (most recent call last):
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 180, in finish
_response
self.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 279, in write
self._write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 775, in write
self._sock.sendall(b)
ConnectionResetError: [WinError 10054] Foi forçado o cancelamento de uma conexão existente pelo host remoto
[21/Sep/2017 23:32:44] "GET /media/posts/03_-_The_Mute.mp3 HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 53114)
Traceback (most recent call last):
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 180, in finish
_response
self.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 279, in write
self._write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 775, in write
self._sock.sendall(b)
ConnectionResetError: [WinError 10054] Foi forçado o cancelamento de uma conexão existente pelo host remoto
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "C:\Users\eduardo\Envs\ProExC\lib\site-packages\django\core\servers\basehttp.py", line 88, in handle_erro
r
super(ServerHandler, self).handle_error()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 368, in handle
_error
self.finish_response()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 180, in finish
_response
self.write(data)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 331, in send_h
eaders
if not self.origin_server or self.client_is_modern():
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 344, in client
_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 639, in process_re
quest_thread
self.finish_request(request, client_address)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 361, in finish_req
uest
self.RequestHandlerClass(request, client_address, self)
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\socketserver.py", line 696, in __init__
self.handle()
File "C:\Users\eduardo\Envs\ProExC\lib\site-packages\django\core\servers\basehttp.py", line 155, in handle
handler.run(self.server.get_app())
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\handlers.py", line 144, in run
self.close()
File "c:\users\eduardo\appdata\local\programs\python\python36-32\Lib\wsgiref\simple_server.py", line 35, in cl
ose
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
---------------------------------------
编辑:
使用 Django 1.11.3, window 10,经过 Opera 和 Chrome 测试,使用 gulp 运行服务器
**编辑2:**
嘿,如果 html 中有 iframe 标记,错误只会发生!!
最佳答案
看来这是一个 python 错误:
Django 票:https://code.djangoproject.com/ticket/26995 python 票:https://bugs.python.org/issue14574
还没有设法解决,如果可以的话我会编辑这个答案详细解释如何解决它。
编辑
这似乎是 chrome 上的错误。我没有想到,因为我正在使用 Opera,但 Opera 也使用 Chromium。在 Internet Explorer 中没有显示错误。
https://code.djangoproject.com/ticket/21227#no1
这是错误跟踪器
关于python - 类型错误 : 'NoneType' object is not subscriptable followed by AttributeError: 'NoneType' object has no attribute 'split' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46355998/
我目前正在尝试定义函数,但遇到了这个错误。我只是想做一个简单的函数,用户输入 2 个数字,然后将它们相乘。也请尽可能简单地解释我做错了什么。 (我是菜鸟) def userinput(): w
使用IPtools python 包我试图查看 IP 地址是否在特定范围内。这是我的代码: for line in g: org= line.split("|")[0] ranges
输入 [['1','2','3'],['a','b','c'],['6','7','8'],['e','f','g']] 输出应该是: 1, 2, 3a, b, c6, 7, 8e, f, g Cod
我目前正在使用 lambda 使 tkinter 按钮依次执行两件事: def classManip(): cManip = tk.Toplevel() cManip.title
我正在学习Python,作为练习,我编写了一些代码来查找用户定义函数的导数。代码如下。 def fx(value, function): x = value return eval(f
使用 Django。我有以下模型: class Postagem(models.Model): id = models.AutoField(primary_key=True, editable=Fal
我正在尝试为给定的数据集选择重要的特征(或者至少了解哪些特征解释更多的变异性)。为此,我使用 ExtraTreesClassifier 和 GradientBoostingRegressor - 然后
刚刚获得了SDXL模型的访问权限,希望为即将发布的版本进行测试...不幸的是,我们当前用于我们服务的代码似乎不能与稳定ai/稳定-扩散-xl-base-0.9一起工作,我不完全确定SDXL有什么不同,
通常,当我尝试使用BeautifulSoup解析网页时,BeautifulSoup函数会得到NONE结果,否则就会引发AttributeError。。以下是一些独立的(即,由于数据是硬编码的,不需要访
通常,当我尝试使用BeautifulSoup解析网页时,BeautifulSoup函数会得到NONE结果,否则就会引发AttributeError。。以下是一些独立的(即,由于数据是硬编码的,不需要访
我想遍历可迭代列表,但要求某些元素的类型可以是 None。 这看起来像这样: none_list = [None, [0, 1]] for x, y in none_list: print("
我得到object is not subscriptable在非空查询结果上。当我打印时 c.fetchone()它打印了正确的结果,但是当我检查类型时它显示 import sqlite3 conn
我在第 15 行收到此错误,但我不明白为什么。有任何想法吗?看来属性已经明确定义了,所以我完全不知所措。任何帮助将非常感激。AttributeError:“NoneType”对象没有属性“Sheets
我尝试对 Chrome WebDriver 进行子类化以包含一些初始化和清理代码,但随后 Python 提示创建的对象设置为 None: import glob import selenium imp
这个问题已经有答案了: Why do I get AttributeError: 'NoneType' object has no attribute 'something'? (10 个回答) 已关
这个问题已经有答案了: Why does the print function return None? (1 个回答) 已关闭 6 年前。 我对 Python 还很陌生。我正在制作一个生成器,可以为
我正在尝试比较两个表( table_a 和 table_b )并减去 table_a 的最后一列从table_b的最后一列开始。但是,table_a 包含一个额外的行,导致我得到 NoneType错误
当“文件名”是一个存在的文件时,这段代码运行良好……但是当它不存在时……我不断收到同样的错误:TypeError: 'NoneType' 对象不可迭代 (Errno 2) 尽管我从不迭代任何东西,除非
我在下面的代码中收到“NoneType”对象不可迭代的 TypeError。下面的代码用于使用 pyautogui 滚动 digits 文件夹中的 10 张图像(命名为 0 到 9,以图像中的 # 命
我有一段代码表现得很奇怪。 一开始,我导入了一个模块,它是 C 库的 python 绑定(bind)。 try: import pyccn except: print "ERROR:
我是一名优秀的程序员,十分优秀!