找不到页面 (404) - Django 网址和视图
Page not found (404) - Django urls and views
我正在尝试用 Django 制作一个网络服务器来制作 "parrot bot"。
我正在使用
python3.5
姜戈
apache2.4
我遇到的错误:
Page not found (404)
Request Method: GET
Request URL: http://54.95.30.145/
Using the URLconf defined in bot.urls, Django tried these URL patterns, in this order:
^keyboard/
^message
The empty path didn't match any of these.
这是我的项目bot/urls.py代码。
from django.conf.urls import url, include
urlpatterns = [
url(r'',include('inform.urls')),
]
这是我的应用程序 inform/urls.py 代码。
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^keyboard/',views.keyboard),
url(r'^message',views.message),
]
这是我的 inform/views.py 代码。
from django.http import JsonResponse
def keyboard(request):
return JsonResponse({
'type' : 'text',
})
def message(request):
message = ((request.body).decode('utf-8'))
return_json_str = json.loads(message)
return_str = return_json_str['contetn']
return JsonResponse({
'message': {
'text' : return_str
}
})
请帮助我。
错误只是您没有为您的 root
地址 (http://54.95.30.145/
) 定义任何 url patterns
。
要解决此问题,请在 project bot/urls.py
中为 home/root 地址添加一个 url 模式,如下所示
from django.conf.urls import url, include
def root_view(request):
return JsonResponse({"message": "This is root"})
urlpatterns = [
url(r'^$', root_view),
url(r'', include('inform.urls')),
]
我正在尝试用 Django 制作一个网络服务器来制作 "parrot bot"。
我正在使用 python3.5 姜戈 apache2.4
我遇到的错误:
Page not found (404)
Request Method: GET
Request URL: http://54.95.30.145/
Using the URLconf defined in bot.urls, Django tried these URL patterns, in this order:
^keyboard/
^message
The empty path didn't match any of these.
这是我的项目bot/urls.py代码。
from django.conf.urls import url, include
urlpatterns = [
url(r'',include('inform.urls')),
]
这是我的应用程序 inform/urls.py 代码。
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^keyboard/',views.keyboard),
url(r'^message',views.message),
]
这是我的 inform/views.py 代码。
from django.http import JsonResponse
def keyboard(request):
return JsonResponse({
'type' : 'text',
})
def message(request):
message = ((request.body).decode('utf-8'))
return_json_str = json.loads(message)
return_str = return_json_str['contetn']
return JsonResponse({
'message': {
'text' : return_str
}
})
请帮助我。
错误只是您没有为您的 root
地址 (http://54.95.30.145/
) 定义任何 url patterns
。
要解决此问题,请在 project bot/urls.py
from django.conf.urls import url, include
def root_view(request):
return JsonResponse({"message": "This is root"})
urlpatterns = [
url(r'^$', root_view),
url(r'', include('inform.urls')),
]