python - Django,2.0.4 路径不起作用,如何解决?
问题描述
今天第一次安装了 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')
解决方案
/
如果您想获得没有附加路径的页面,请不要写。例如:http://example.com/
代替:
path('/', include("someapi.urls")),
类型:
path('', include("someapi.urls")),
此外,django 需要应用程序的名称,以防您想包含应用程序。在这里阅读
记住!标准路径
/
不是
你输入额外/
的,最后你得到//
推荐阅读
- python - 为特定行和列绘制 DataFrame Python
- sql-server - SQL CriteriaBuilder API 中的投射日期
- python - 如何在 django 中仅存储云图像 url?
- r - 比较不同数据帧的不同列和标志匹配
- r - 每次唯一字符串值在 r 中的其他列中具有 TRUE 值时,如何重新构造数据以计数/绘图?
- autodesk-forge - FORGE Viewer 长时间使用偶尔卡顿,无法加载模型
- python-3.x - is operator python 的奇怪行为
- image - 将图像发送到 Web 服务器时,我们实际发送的是什么?
- python - 用于 asyncpg 的 Python 上下文管理器
- android - 在 UE4 中的 android 包时发生 Crashlytic 构建错误