Python django中的TypeError和NoReverseMatch
当我转到Python django中的TypeError和NoReverseMatch,python,django,Python,Django,当我转到/projects时,我在/projects/Reverse中找到了“未找到详细信息”的NoReverseMatch“详细信息”不是有效的视图函数或模式名称 当我转到/projects/some number时,我在/projects/1处得到TypeError/ “Project”对象不可编辑 路径 main migrations templates detail.html home.html proceed
/projects
时,我在/projects/Reverse
中找到了“未找到详细信息”的NoReverseMatch“详细信息”不是有效的视图函数或模式名称
当我转到/projects/some number
时,我在/projects/1处得到TypeError/
“Project”对象不可编辑
路径
main
migrations
templates
detail.html
home.html
proceed.html
project.html
__init_.py
admin.py
apps.py
models.py
tests.py
views.py
portfolio
__init_.py
asgi.py
settings.py
urls.py
wsgi.py
db.sqlite3
manage.py
视图.py
from django.shortcuts import render, get_object_or_404
from .models import Project
# Create your views here.
def home(request):
return render(request, "home/home.html")
def project(request):
projects = Project.objects.all()
return render(request, "home/project.html", {'projects':projects })
def detail(request, project_id):
oof = get_object_or_404(Project, pk=project_id)
return render(request, 'home/detail.html', {'projectss': oof})
"""portfolio URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from main import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
path('projects/', views.project),
path('projects/<int:project_id>/', views.detail)
]
"""
Django settings for portfolio project.
Generated by 'django-admin startproject' using Django 3.0.10.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_4d4kcc1u=5xch1a_un*j2e8^_ca7d1(r+d60@_67o^l&@vu0d'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'portfolio.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'portfolio.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
from django.db import models
# Create your models here.
class Project(models.Model):
title = models.CharField(max_length=100)
description = models.CharField(max_length=100000000)
url = models.CharField(max_length=100000000000000, blank=True)
madef = models.CharField(max_length=100, blank=True)
point1 = models.CharField(max_length=100000000000000, blank=True)
point2 = models.CharField(max_length=100000000000000, blank=True)
point3 = models.CharField(max_length=100000000000000, blank=True)
point4 = models.CharField(max_length=100000000000000, blank=True)
point5 = models.CharField(max_length=100000000000000, blank=True)
point6 = models.CharField(max_length=100000000000000, blank=True)
point7 = models.CharField(max_length=100000000000000, blank=True)
point8 = models.CharField(max_length=100000000000000, blank=True)
def __str__(self):
return self.title
from django.contrib import admin
from .models import Project
# Register your models here.
admin.site.register(Project)
detail.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
<link rel="stylesheet" href="https://static.pingendo.com/bootstrap/bootstrap-4.3.1.css">
</head>
<body >
<div class="py-5" style=" background-image: linear-gradient(to bottom, rgb(0, 0, 0), rgb(0, 0, 0)); background-position: center center; background-size: 100%; background-repeat: repeat;">
<div class="container">
<div class="row">
<div class="text-center mx-auto col-md-12">
<h1 class="text-light">Proceed to external site</h1>
</div>
</div>
</div>
</div>
<div class="py-5 text-center" style=" background-image: linear-gradient(to bottom, rgb(0, 0, 0), rgb(0, 0, 0)); background-position: top left; background-size: 100%; background-repeat: repeat;">
<div class="container">
<div class="row">
{% for project in projectss %}
<div class="mx-auto col-lg-5 col-md-7 col-10">
<h1 class="text-white mb-5">{project.title}</h1>
<h3 class="mb-3 text-white">{project.point1}</h3>
<h3 class="mb-3 text-white">{project.point1}</h3>
<h3 class="mb-3 text-white">{project.point1}</h3>
<h3 class="mb-3 text-white">{project.point1}</h3>
<h3 class="mb-3 text-white">{project.point1}</h3>
<h3 class="mb-3 text-white">{project.point1}</h3>
<h3 class="mb-3 text-white">{project.point1}</h3>
<h3 class="mb-3 text-white">{project.point1}</h3>
<a class="btn btn-primary btn-lg mt-5" href="{project.url}">Go to site</a>
</div>
{% endfor %}
</div>
</div>
</div>
<div class="py-3" style=" background-image: linear-gradient(to bottom, rgb(0, 0, 0), rgb(0, 0, 0)); background-position: top left; background-size: 100%; background-repeat: repeat;">
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<p class="mb-0 pb-3"> <a href="mailto:work.arpit7@gmail.com">work.arpit7@gmail.com</a> </p><big>
<p class="text-white">Follow me on social media!</p>
</big>
</div>
</div>
<div class="row" style="padding-bottom: 2%">
<div class="col-md-12 d-flex align-items-center justify-content-center my-3"> <a href="#">
<i class="d-block fa fa-instagram text-muted fa-lg mx-2"></i>
</a> <a href="#">
<i class="d-block fa fa-reddit text-muted fa-lg mx-2"></i>
</a> <a href="#">
<i class="d-block fa fa-twitter text-muted fa-lg ml-2"></i>
</a> </div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
<link rel="stylesheet" href="https://static.pingendo.com/bootstrap/bootstrap-4.3.1.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark" style=" background-image: linear-gradient(to bottom, rgb(0, 0, 0), rgb(0, 0, 0)); background-position: top left; background-size: 100%; background-repeat: repeat;">
<div class="container"> <a class="navbar-brand" href="#">
<i class="fa d-inline fa-lg fa-circle-o"></i>
<b>Arpit's portfolio</b>
</a> <button class="navbar-toggler navbar-toggler-right border-0" type="button" data-toggle="collapse" data-target="#navbar11">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbar11">
<ul class="navbar-nav ml-auto">
<li class="nav-item"> <a class="nav-link text-white" href="#">Portfolio projects</a> </li>
<li class="nav-item"> <a class="nav-link text-white" href="#">Blog</a> </li>
<li class="nav-item"> <a class="nav-link text-white" href="#">Contact</a> </li>
</ul> <a class="btn btn-primary navbar-btn ml-md-2 text-white">Hire me</a>
</div>
</div>
</nav>
<div class="py-5" style=" background-image: linear-gradient(to bottom, rgb(0, 0, 0), rgb(0, 0, 0)); background-position: center center; background-size: 100%; background-repeat: repeat;">
<div class="container">
<div class="row">
<div class="text-center mx-auto col-md-12">
<h1 class="text-light">Some of my portfolio projects</h1>
</div>
</div>
</div>
</div>
<div class="py-5" style=" background-image: linear-gradient(to bottom, rgb(0,0,0), rgb(0,0,0)); background-position: center center; background-size: 100%; background-repeat: repeat;" >
<div class="container">
<div class="row">
<div class="text-center container">
<div class="row" >
{% for project in projects %}
<div class="card mx-5" style="width: 30%; height:43%; margin-bottom: 5%;">
<div class="card-body" >
<h3 class="card-title text-dark">{{ project.title }}</h3>
<h5 class="card-text text-dark mt-4">{{ project.description }}</h5>
<h3 style="margin-top : 12%">Made using {{ project.madef }}</h3>
<a href="{% url 'detail' project.id %}" class="btn btn-primary" style="margin-top : 18%">Check out</a>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
<div class="py-3" style=" background-image: linear-gradient(to bottom, rgb(0, 0, 0), rgb(0, 0, 0)); background-position: top left; background-size: 100%; background-repeat: repeat;">
<div class="container">
<div class="row">
<div class="col-md-12 text-center">
<p class="mb-0 pb-3"> <a href="mailto:work.arpit7@gmail.com">work.arpit7@gmail.com</a> </p><big>
<p class="text-white">Follow me on social media!</p>
</big>
</div>
</div>
<div class="row">
<div class="col-md-12 d-flex align-items-center justify-content-center my-3"> <a href="#">
<i class="d-block fa fa-instagram text-muted fa-lg mx-2"></i>
</a> <a href="#">
<i class="d-block fa fa-reddit text-muted fa-lg mx-2"></i>
</a> <a href="#">
<i class="d-block fa fa-twitter text-muted fa-lg ml-2"></i>
</a> </div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
型号.py
from django.shortcuts import render, get_object_or_404
from .models import Project
# Create your views here.
def home(request):
return render(request, "home/home.html")
def project(request):
projects = Project.objects.all()
return render(request, "home/project.html", {'projects':projects })
def detail(request, project_id):
oof = get_object_or_404(Project, pk=project_id)
return render(request, 'home/detail.html', {'projectss': oof})
"""portfolio URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from main import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
path('projects/', views.project),
path('projects/<int:project_id>/', views.detail)
]
"""
Django settings for portfolio project.
Generated by 'django-admin startproject' using Django 3.0.10.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_4d4kcc1u=5xch1a_un*j2e8^_ca7d1(r+d60@_67o^l&@vu0d'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'portfolio.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'portfolio.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
from django.db import models
# Create your models here.
class Project(models.Model):
title = models.CharField(max_length=100)
description = models.CharField(max_length=100000000)
url = models.CharField(max_length=100000000000000, blank=True)
madef = models.CharField(max_length=100, blank=True)
point1 = models.CharField(max_length=100000000000000, blank=True)
point2 = models.CharField(max_length=100000000000000, blank=True)
point3 = models.CharField(max_length=100000000000000, blank=True)
point4 = models.CharField(max_length=100000000000000, blank=True)
point5 = models.CharField(max_length=100000000000000, blank=True)
point6 = models.CharField(max_length=100000000000000, blank=True)
point7 = models.CharField(max_length=100000000000000, blank=True)
point8 = models.CharField(max_length=100000000000000, blank=True)
def __str__(self):
return self.title
from django.contrib import admin
from .models import Project
# Register your models here.
admin.site.register(Project)
admin.py
from django.shortcuts import render, get_object_or_404
from .models import Project
# Create your views here.
def home(request):
return render(request, "home/home.html")
def project(request):
projects = Project.objects.all()
return render(request, "home/project.html", {'projects':projects })
def detail(request, project_id):
oof = get_object_or_404(Project, pk=project_id)
return render(request, 'home/detail.html', {'projectss': oof})
"""portfolio URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from main import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
path('projects/', views.project),
path('projects/<int:project_id>/', views.detail)
]
"""
Django settings for portfolio project.
Generated by 'django-admin startproject' using Django 3.0.10.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '_4d4kcc1u=5xch1a_un*j2e8^_ca7d1(r+d60@_67o^l&@vu0d'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'portfolio.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'portfolio.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
from django.db import models
# Create your models here.
class Project(models.Model):
title = models.CharField(max_length=100)
description = models.CharField(max_length=100000000)
url = models.CharField(max_length=100000000000000, blank=True)
madef = models.CharField(max_length=100, blank=True)
point1 = models.CharField(max_length=100000000000000, blank=True)
point2 = models.CharField(max_length=100000000000000, blank=True)
point3 = models.CharField(max_length=100000000000000, blank=True)
point4 = models.CharField(max_length=100000000000000, blank=True)
point5 = models.CharField(max_length=100000000000000, blank=True)
point6 = models.CharField(max_length=100000000000000, blank=True)
point7 = models.CharField(max_length=100000000000000, blank=True)
point8 = models.CharField(max_length=100000000000000, blank=True)
def __str__(self):
return self.title
from django.contrib import admin
from .models import Project
# Register your models here.
admin.site.register(Project)
我是个新手,不知道哪里出了错
我使用的是Djnago 3.0.10写以下内容毫无意义:
{% for project in projectss %}
…
{% endfor %}
要呈现变量,请使用双花括号,因此{{…}
,而不是{…}
对于NoReverseMatch
错误,您需要为视图提供一个正确的名称,因此:
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home),
path('projects/', views.project),
path('projects/<int:project_id>/', views.detail, name='detail')
]
urlpatterns=[
路径('admin/',admin.site.url),
路径(“”,视图。主页),
路径('projects/',views.project),
路径('projects/',views.detail,name='detail')
]
我认为您没有正确定义模板目录。它不知道从哪里获取模板。请尝试在设置中的模板['DIRS']
中添加'main/templates/'
。py您应该做一次更改,而不是发布整个代码。非常感谢