I'm trying to import a list from a file in another directory into my urls.py
file. I have included the directory in the settings.py
file, ran the ./manage.py makemigrations
& the ./manage.py migrate
Django commands, and imported the function and the file into the urls.py
file.
Here is my current code:
urls.py
:
from django.contrib import admin
from django.urls import path
from apps.accounts.urls import account_urlpatterns
urlpatterns = [
path('admin/', admin.site.urls),
]
urlpatterns += accounts_urlpatterns
settings.py
:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#
'rest_framework',
'rest_framework.authtoken',
'djoser',
#
'apps.accounts'
]
apps/accounts/urls.py
:
from django.conf.urls import url, include
accounts_urlpatterns = [
url(r'^api/v1/', include('djoser.urls')),
url(r'^api/v1/', include('djoser.urls.authtoken')),
]
the error message:
ImportError: cannot import name 'account_urlpatterns' from 'apps.accounts.urls' (/Users/{name}/programming/dj/backend/server/apps/accounts/urls.py)
and the project structure:
.
└── server
├── apps
│ └── accounts
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── migrations
│ │ └── __init__.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── db.sqlite3
├── manage.py
└── server
├── __init__.py
├── asgi.py
├── settings.py
├── urls.py
└── wsgi.py
I appreciate any advice - thank you in advance!
question from:
https://stackoverflow.com/questions/65831552/why-wont-the-urls-py-file-in-my-django-project-let-me-import-this-file 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…