前提・実現したいこと
今回動作確認するためにDjangoでサンプル作成していてエラーがが出てしまい。
行き詰まっています。
1.プロジェクトを作成後、app1というアプリを追加しました。
発生している問題・エラーメッセージ
Exception in thread django-main-thread: Traceback (most recent call last): File "/Users/user1/opt/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner self.run() File "/Users/user1/opt/anaconda3/lib/python3.7/threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/utils/autoreload.py", line 53, in wrapper fn(*args, **kwargs) File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 118, in inner_run self.check(display_num_errors=True) File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/core/management/base.py", line 396, in check databases=databases, File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/core/checks/registry.py", line 70, in run_checks new_errors = check(app_configs=app_configs, databases=databases) File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/core/checks/urls.py", line 13, in check_url_config return check_resolver(resolver) File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/core/checks/urls.py", line 23, in check_resolver return check_method() File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/urls/resolvers.py", line 408, in check for pattern in self.url_patterns: File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/urls/resolvers.py", line 589, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/urls/resolvers.py", line 582, in urlconf_module return import_module(self.urlconf_name) File "/Users/user1/opt/anaconda3/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 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 728, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/Users/user1/admin/admin/urls.py", line 6, in <module> path('',include('app1.urls')), File "/Users/user1/opt/anaconda3/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include urlconf_module = import_module(urlconf_module) File "/Users/user1/opt/anaconda3/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 'app1.urls'
該当のソースコード
ファイル構成
├── admin
│ ├── init.py
│ ├── pycache
│ │ ├── init.cpython-37.pyc
│ │ ├── settings.cpython-37.pyc
│ │ ├── urls.cpython-37.pyc
│ │ └── wsgi.cpython-37.pyc
│ ├── asgi.py
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
├── app1
│ ├── app1
│ │ ├── init.py
│ │ ├── apps.py
│ │ ├── asgi.py
│ │ ├── forms.py
│ │ ├── models.py
│ │ ├── templates
│ │ │ └── Upload.html
│ │ ├── urls.py
│ │ ├── views.py
│ │ └── wsgi.py
│ └── manage.py
├── db.sqlite3
├── manage.py
└── media
setting.py
一部抜粋 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app1', ]
admin/urls.py
from django.contrib import admin from django.urls import path ,include urlpatterns = [ path('admin/', admin.site.urls), path('',include('app1.urls')), ]
app1/urls.py
from django.contrib import admin from django.urls import include, path from .views import upload from django.conf import settings from . import views urlpatterns = [ path('upload/',upload,name='upload'), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
試したこと
admin/urls.pyの
path('',include('app1.urls')),
を削除すると、runserverが起動することを確認できています。
エラーからも原因ということはわかりますが、解消できずに困っています。
また、確認に必要な情報に不足があればお知らせ下さい。
よろしくお願い致します。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。