我使用Pycharm,django2.0.4 我昨天开始了Django。 我遇到了一个错误。
使用chatbottest.urls中定义的URLconf,Django按以下顺序尝试了这些URL模式: 管理员/ 2. globalHaksik /
空路径与其中任何一个都不匹配。 enter image description here
setting.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'globalHaksik',
]
chatbottest \ urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('globalHaksik/', include('globalHaksik.urls')),
]
globalHaksik \ urls.py
from django.urls import path
from . import views
urlpatterns = [
path('keyboard/', views.keyboard),
]
views.py
from django.http import JsonResponse
def keyboard(request):
return JsonResponse({
'type': 'buttons',
'buttons': ['학식', '배달음식']
})
如果我在此网站上查找相同的错误,我不知道正确的答案。 请好好回答我。
答案 0 :(得分:0)
更新:您似乎只是想访问通往views.keyboard的网址。因此,您需要访问的网址是/globalHaksik/keyboard/
(而不只是/keyboard
),因为chatbottest \ urls.py中定义的路径中包含globalHaksik/
:
path('globalHaksik/', include('globalHaksik.urls')),
如果您尝试访问/
,则需要按如下方式添加空模式:
chatbottest \ urls.py
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('', views.your_view_name),
path('admin/', admin.site.urls),
path('globalHaksik/', include('globalHaksik.urls')),
]
如果您尝试访问/globalHaksik/
,则需要将空模式添加到globalHaksik \ urls.py:
globalHaksik \ urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.your_view_name),
path('keyboard/', views.keyboard),
]