我有一个登录系统:
def login(request):
title = "Login"
if request.user.is_authenticated():
return HttpResponseRedirect('/')
form = UserLoginForm(request.POST or None)
if request.POST and form.is_valid():
username = form.cleaned_data.get('username')
password = form.cleaned_
我在任何地方都找不到明确的指南来说明什么是正确的。例如,我的django网站使用了一个django包--双因素-auth。我想向模板中添加一个上下文变量并显示它。我在模板文件夹和同名模板文件中创建了一个文件夹two_factor。那部分很简单。但是我也需要继承泛型视图来添加我的上下文(当然,我不想改变第三方包的源代码)。为此,我在项目中创建了一个新应用程序,并将其命名为two_factor_custom,并向views.py添加了以下代码:
from binascii import unhexlify
from base64 import b32encode
from two_factor.v
我想循环遍历一个可迭代的列表,但是要求某些元素可以是None类型的。
这可能是这样的:
none_list = [None, [0, 1]]
for x, y in none_list:
print("I'm not gonna print anything!")
但是,这将提示TypeError: 'NoneType' object is not iterable。
目前,我发现错误,然后处理NoneType。对于我的用例,这会导致大量重复的代码,因为我基本上替换了None值,并按照最初在For -循环中的计划做了同样的事情。
try:
我正在尝试使用Django-Q在Django项目中创建一些预定任务。问题是,每个调度任务都失败,引发下一个异常:
'NoneType' object is not callable : Traceback (most recent call last):
File "/home/ubuntu/.virtualenvs/gamesquare-pre/lib/python3.6/site-packages/django_q/cluster.py", line 432, in worker
res = f(*task["args"], **task[&
将None传递给Python的list构造函数是一个TypeError
>>> l = list(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
但是,使用方括号实例化list是很好的;在内置函数中使用None也很好:
>>> l = [None]
>>> l.append(None)
&
我试图将romeo.txt中的每个单词添加到空列表中。
我认为这段代码没问题,但是python3返回一个回溯,说
文件"test.py",第13行,如果我在lst: TypeError:类型为'NoneType‘的参数不可迭代
这是我的密码:
fh = open("romeo.txt")
lst = list()
words = fh.read()
list1 = words.split()
for i in list1:
if i in lst:
continue
else:
lst = lst.
在迭代Json文件时,我正面临这个错误'NoneType' object is not iterable。
我的代码:
import nltk
import json
from nltk import word_tokenize
with open('full_format_recipes.json', 'r') as myfile:
data=myfile.read()
obj = json.loads(data)
result=[]
for a in obj:
for b in a.get("ingredients")
当我试图在我的项目中迁移或创建超级用户时,我得到了这个错误。
SystemCheckError: System check identified some issues:
ERRORS:
?: (admin.E404) 'django.contrib.messages.context_processors.messages' must be enabled in DjangoTemplates (TEMPLATES) in order to use the admin application.
我不应该得到错误,因为它是一个入门项目,我甚至没有使用模板。此参数'dja
在使用Apache和mod_wsgi (在mod_wsgi上)设置Django时,我遵循了TypeError,但是每当我尝试访问一个静态文件时,我都会得到以下错误:类型为'NoneType‘的TypeError at / static /js/map.js对象没有len()
这与document_root有关:
C:\Python27\lib\site-packages\django\core\handlers\base.py in get_response
TypeError("object of type 'NoneType' has no len()
在我的django项目中,我有一个扩展,我所有的模板{% base.html 'base.html‘%}都来自它。在基本模板中,我想对我所有算法列表执行此操作。
{% for algorithm in algorithms %}
# list them out as links in nav bar
{% endfor %}
但我不会将算法传递给库,因为它只是扩展了其他模板。
我不知道怎么解决这个问题。我的想法是在基本模板中使用{% load %},这基本上会。
from algorithms.models import Algorithm
from django import
我正在使用Python中的Beautiful从HTML文件中刮取一些数据。在某些情况下,Beautiful返回包含string和NoneType对象的列表。我想过滤掉所有的NoneType对象。
在Python中,包含NoneType对象的列表是不可迭代的,因此列表理解不是其中的一个选项。具体来说,如果我有一个包含lis的列表NoneTypes,并且我尝试执行类似于[x for x in lis (some condition/function)]的操作,Python会抛出错误TypeError: argument of type 'NoneType' is not itera