python - urls.E004 路径在 Python Django 中不起作用
问题描述
因此,每次我尝试运行服务器时,它都会发送此错误:
?: (urls.E004) 你的 URL 模式 b'["Aquaman", "Glass", "Bumblebee", "Polar", "Bohemian Rhapsody", "Widows", "Creed II", "Escape Room", "Dragon超级球:布罗利,“凡人引擎”,“6.9”,“6.9”,“6.5”,“6.4”,“8.2”,“6.7”,“6.6”,“6.6”,“7.5”,“5.9” , “297802”, “450465”, “424783”, “483906”, “424694”, “401469”, “480530”, “522681”, “503314”, “428078”, “143”, “129”, “ 114”、“119”、“135”、“130”、“130”、“100”、“101”、“128”、“动作”、“Thriller", "Action", "Action", "Drama", "Crime", "Drama", "Horror", "Action", "Science Fiction"]' 无效。确保 urlpatterns 是 path() 的列表和/或 re_path() 实例。
这是代码
import requests
import json
from django.conf.urls import url, include, re_path
from django.contrib import admin
from django.http import JsonResponse, HttpResponse
from django.urls import path
def lookForValue(value, list, moves, number_of_values):
i = 0
valuesFound = []
for string in list:
if string == value and i < number_of_values:
pointer = list.index(string)
valuesFound.append(list[pointer + moves])
i += 1
list[pointer] = None
return valuesFound
def getData(apiurl):
payload = {}
data = requests.request("GET", apiurl, data=payload)
data = data.text
data = data.split('\"')
return data
url = "https://api.themoviedb.org/3/discover/movie?api_key=31563efa3563f61e00e5f0e2ed88c4bb&language=en-US&sort_by=popularity.desc&include_adult=false&include_video=false&page=1"
list = getData(url)
titles = []
release_dates = []
ratings = []
uids = []
runtimes = []
genres = []
total = []
i = 0
j = 0
titles = lookForValue('title', list, 2, 10)
release_dates = lookForValue('release_date', list, 2, 10)
ratings = lookForValue('vote_average', list, 1, 10)
uids = lookForValue('id', list, 1, 10)
for string in ratings:
ratings[ratings.index(string)] = string[1:4]
for string in uids:
uids[uids.index(string)] = string[1:7]
for string in uids:
response = getData('https://api.themoviedb.org/3/movie/' + string + '?api_key=31563efa3563f61e00e5f0e2ed88c4bb&language=en-US')
genres.append(lookForValue('genres',response, 6, 1)[0])
runtimes.append(lookForValue('runtime', response,1, 1)[0])
for i in range(0, 10):
runtimes[i] = runtimes[i][1:len(runtimes[i])]
runtimes[i] = runtimes[i][0:len(runtimes[i]) - 1]
total += titles
total += ratings
total += uids
total += runtimes
total += genres
def createJsonResponse(object):
return JsonResponse(object, safe = False)
urlpatterns = [
path('popularmovies', include(createJsonResponse(total)))
]
谢谢您的帮助!
解决方案
推荐阅读
- javascript - 在函数上下文中使用 this 关键字的 Javascript 回调
- r - R光栅堆栈子集按日期
- gitea - (已修复)重新打开意外关闭的 gitea PR
- ios - 当更改源为共享扩展时,@FetchRequest 结果未在 SwiftUI 中更新
- laravel - Google Drive API 获取 Laravel 特定文件夹中的文件
- android-studio - Android Studio 4.1 Canary 9 201.6466190-linux 发行版已损坏?
- css - 如何从选定页面中删除滚动指示器
- swift - 在firebase中使用分配给用户配置文件的图像并将其附加到配置文件页面
- python - 使用__inti__时python中没有参数错误
- r - R facet wrap,每个 wrap 都有自己的比例