Reputation: 317
I have been trying to make a django project, but I can't make an app.
python3 manage.py startapp app
In settings.py:
INSTALLED_APPS = [
'app',
<All other django.things>
]
In urls.py:
from django.urls import path, include
urlpatterns = [
path('app/', include('app.urls')),
path('admin/', admin.site.urls),
]
Note: These are exerpts
But I still get this error: ModuleNotFoundError: No module named 'app.urls'
Upvotes: 0
Views: 1555
Reputation: 545
Since you are pointing to 'app/urls' and there is no file called urls in your app folder, you externally have to create urls.py file in your app folder.
urls.py
from django.urls import path, include
from . import views
urlpatterns = [
path('', view.your_view_name),
]
Upvotes: 1
Reputation: 337
python manage.py startapp app
cd app
touch urls.py
//(if you are on mac or linux) or create from your editor. Make sure to add url config in urls.py of the app or it will raise error
in settings.py
in the INSTALLED_APPS
list add your app
INSTALLED_APPS = [
"app.apps.AppConfig"
]
Upvotes: 1
Reputation: 24562
When you execute python3 manage.py startapp app
django create following directory structure.
app/
__init__.py
admin.py
apps.py
migrations/
__init__.py
models.py
tests.py
views.py
Which means urls.py
file is not included by default, hence you have to create one.
Upvotes: 1