今天第一次安装了django的第二个版本并且从这个狗屎中震惊,使用url取消并删除了正常的路由我知道有一个re_path但是这不是它!
一般来说,一切都是按照说明完成的 django,但它不起作用没有看到任何巧合!
错误
Using the URLconf defined in src.urls, Django tried these URL patterns, in this order:
admin/
/
^media\/(?P<path>.*)$
The empty path didn't match any of these.
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
主要是urs.py
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('/', include("someapi.urls")),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
来自我的应用的网址
from django.contrib import admin
from django.urls import path
from .views import handle_verification, send_message
from django.conf.urls import include, url
urlpatterns = [
path('', handle_verification, name='handle_verification'),
path('send/<str:recipient>/<str:txt>/', send_message, name='send_message'),
]
我的观点
import random
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.shortcuts import render, get_object_or_404, redirect
from django.http import JsonResponse, Http404, HttpResponse
import requests
import json
def handle_verification(request):
print("Handling Verification.")
if request.args.get("hub.mode") == "subscribe" and request.args.get("hub.challenge"):
if not request.args.get("hub.verify_token") == "my_voice_is_my_password_verify_me":
return "Verification token mismatch", 403
return request.args["hub.challenge"], 200
context = {good:"I love HENTAI"}
return render(request, 'home.html', context)
def send_message(request, token, recipient, text):
if request.method == 'POST':
data = request.POST
recipient = data.get("recipient")
text = data.get("text")
print(payload)
r = requests.post("https://graph.facebook.com/v2.6/me/messages",
params={"access_token": token},
data=json.dumps({
"recipient": {"id": recipient},
"message": {"text": text}
}),
headers={'Content-type': 'application/json'})
if r.status_code != requests.codes.ok:
print(r.text)
return Http404
else:
return HttpResponse('Got')
答案 0 :(得分:1)
如果您想获取没有其他路径的页面,请不要写/
。例如:http://example.com/
而不是:
path('/', include("someapi.urls")),
类型:
path('', include("someapi.urls")),
此外,django需要应用程序的名称,以防您想要包含应用程序。阅读它here
记住!标准路径为
/
而非
您输入了其他/
,最后得到//