python - AttributeError:模块“collection.views”没有属性“create_word”
问题描述
我正在尝试为允许用户为字典创建自己的单词的表单创建路由。
AttributeError: module 'collection.views' has no attribute 'create_word'
每次尝试运行本地服务器时,我都会收到以下错误
错误提醒注意 urls.py 中的这行代码
path('accounts/create_word/', views.create_word, name='registration_create_word'),
不确定是什么问题,因为我已经定义了位于 views.py 中的 create_word 方法
def create_word(request):
form_class = WordForm
# if users are coming from a submitted form, do this
if request.method == 'POST':
#grab the data from the submitted form and apply it to the form
form = form_class(request.POST)
if form.is_valid():
#create an instance but don't save
word = form.save(commit=False)
#set additional details
word.user = request.user
user.slug = slugify(word.name)
#save the object
word.save()
# redirect to newly created word object
return redirect('word_detail', slug=word.slug)
#otherwise create the form
else:
form = form_class()
return render(request, 'words/create_word.html', {
'form': form,
})
我也相信我正确导入了集合视图
from collection.backends import MyRegistrationView
from collection import views
非常感谢澄清我错过了什么或做错了什么
解决方案
推荐阅读
- node.js - 无法更新云 Firestore 中的文档
- three.js - ThreeJS:将对象位置设置为控件目标
- c - 为什么当数字的位数大于4时,结果被破坏
- python - 类导入:ImproperlyConfigured:SECRET_KEY 设置不能为空
- c# - 如何与表单视图中动态添加的控件进行交互?
- java - 游戏的 2d 动画。使用 Libgdx
- javascript - (javaScript: DOM) setAttribute 索引
- android - 在纯 Kotlin 中 2 秒后执行代码
- javascript - 从另一个模块/文件访问函数内部的函数?
- firebase - Firestore 未按预期返回数据