A913830 发表于 2021-11-12 17:52

django HTMLParseError 路由的分组01

1.AttributeError: module 'html.parser' has no attribute 'HTMLParseError'
python和django的版本是多少?你应该是用了不兼容的python和django的组合,一般发生在使用python3.3以上和django1.8以下的组合
pip uninstall django
pip install django

https://static.52pojie.cn/static/image/hrline/line1.png


from django.conf.urls import include, url
from django.contrib import admin
from app01 import views


urlpatterns = [
    url(r'^admin/', include(admin.site.urls)),
    url(r'^$',views.index_page),
    url(r'^page(\d+)$',views.pagen_view),
    ]

from django.shortcuts import HttpResponse

def index_page(request):
    html = " <h1>index_page</h1> "
    return HttpResponse(html)

def pagen_view(request,n):
    html = f" <h1>第{n}个页面</h1> "
    return HttpResponse(html)


url(r'^person/(?P<name>\w+)/(?P<age>\d{1,2})',views.person_view),关键字传参



def person_view(request,**kwargs):
    s = str(kwargs)
    return HttpResponse(s)






A913830 发表于 2021-11-14 15:46

反向解析
url(r'^login/',views.login,name='login_name')


<form action="{% url 'login_name' %}" method="post"></form>

页: [1]
查看完整版本: django HTMLParseError 路由的分组01