首页 > 解决方案 > 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)))
]

谢谢您的帮助!

标签: pythondjango

解决方案


推荐阅读