【发布时间】:2026-01-31 20:45:01
【问题描述】:
views.py
from http.client import HTTPResponse
from django.shortcuts import render
from django.http import HttpResponse,HttpResponseNotFound
# Create your views here.
def index(request,week):
return HTTPResponse(week)
def allweek(request,week):
text=None
if week=='sunday':
text='Sunday is funday and also utilize well'
elif week=='monday':
text='start of week and after break'
elif week=='tuesday':
text='very long meetings'
elif week=='wednesday':
text='finished half of week'
elif week=='thursday':
text='preparing for weekend party day'
elif week=='friday':
text='weekend arrived'
elif week=='saturday':
text='wait is over enjoy tour day!'
else:
return HttpResponseNotFound('Entered wrong week of the day')
return HttpResponse(text)
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('<int:week>',views.index),
path('<str:week>',views.allweek),
]
执行上述代码时出现以下错误 当我尝试在 url 中使用 int 和 str 值来映射相应的视图时,但在映射 int 值时遇到了以下错误。
/challenges/1 处的 AttributeError “int”对象没有属性“makefile”
跑步时
【问题讨论】:
-
请分享完整的回溯。