制作了一个名为Blog的新应用,现在无法导入。 创建了称为产品,页面的基本应用。现在,将另一个名为Blog的应用程序添加到项目中。无法解决迁移问题,终端最终没有名为“博客”的模型导入错误:
这是我的目录结构:
> Dev
> python3
> trydjango
> src
> blog
> migrations
> templates
HTML FILES
PYTHON FILE
> pages
> products
> migrations
> templates
> templates
> trydjango
SETTINGS,URL,WSGI
这是BLOG / models.py文件:
from django.db import models
# Create your models here.
class Article(models.Model):
title = models.CharField(max_length=120)
abstract = models.CharField()
author = models.CharField(max_length=100)
created_on = models.DateTimeField(auto_now_add=True)
这是Blog / view.py文件:
from django.shortcuts import render
from django.views.generic import (
CreateView,
DetailView,
ListView,
UpdateView,
ListView,
DeleteView
)
from .models import Article
# Create your views here.
class ArticleListView(ListView):
queryset = Article.objects.all()
回溯:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Users/kuldeep/Dev/trydjango/lib/python3.7/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/kuldeep/Dev/trydjango/lib/python3.7/site-packages/django/core/management/__init__.py", line 347, in execute
django.setup()
File "/Users/kuldeep/Dev/trydjango/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/kuldeep/Dev/trydjango/lib/python3.7/site-packages/django/apps/registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "/Users/kuldeep/Dev/trydjango/lib/python3.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/Users/kuldeep/Dev/trydjango/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'Blog'
(trydjango) Kuldeeps-MacBook-Pro:src kuldeep$
````
答案 0 :(得分:0)
我知道了。非常令人沮丧,尤其是来自python2。
无论模块是相对的还是绝对的,都必须向模块添加.
。
答案 1 :(得分:0)