我收到:
TemplateDoesNotExist at /skills2/
portfolio/skill_list.html
访问http://127.0.0.1:8000/skills2/
时mysite的/ mysite的/ urls.py
from django.conf.urls import url
from django.contrib import admin
admin.autodiscover()
from portfolio.views import skills, experience, index, v_index, SkillsView
from django.conf.urls import include, url
urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'^skills2/$', SkillsView.as_view(), name='skills'),]
mysite的/组合/ models.py
from django.db import models
class Skill(models.Model):
publish_date = models.DateTimeField(auto_now_add=True)
name = models.CharField(max_length=100, blank=True, default='')
description = models.TextField(default='')
def __str__(self):
return self.name
mysite的/组合/ views.py
from .models import Skill, Experience
class SkillsView(generic.ListView):
model = Skill
mysite的/组合/模板/ index2.html
{% extends "base_generic.html" %}
{% block content %}
<h1>Portf site</h1>
<p>Welcome to <em>My Site</em>, a very basic Django website</p>
<h2>Dynamic content</h2>
<p>The site has the following record counts:</p>
<ul>
<li><strong>Skills:</strong> {{ num_skills }}</li>
<li><strong>Exp:</strong> {{ num_experience }}</li>
</ul>
{% load static %}
<img src="{% static 'oh_i_ah.jpg' %}" alt="My image" style="width:640px;height:473px;"/>
{% endblock %}
mysite的/组合/模板/ base_generic.html
<!DOCTYPE html>
<html lang="en">
<head>
{% block title %}<title>My portfolio web-site</title>{% endblock %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Add additional CSS in static file -->
{% load static %}
<link rel="stylesheet" href="{% static 'css/styles.css' %}">
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-2">
{% block sidebar %}
<ul class="sidebar-nav">
<li><a href="{% url 'v_index' %}">Home</a></li>
<li><a href="{% url 'skills' %}">All skills</a></li>
<li><a href="{% url 'exp' %}">All experience</a></li>
</ul>
{% endblock %}
</div>
<div class="col-sm-10 ">
{% block content %}{% endblock %}
</div>
</div>
</div>
</body>
</html>
mysite的/组合/ skills_list.html
{% extends "base_generic.html" %}
{% block content %}
<h1>Skill List</h1>
{% if item_list %}
<ul>
{% for item in item_list %}
<li>
<a href="{{ items.get_absolute_url }}">{{ items.name }}</a>
</li>
{% endfor %}
</ul>
{% else %}
<p>There are no skill in the library.</p>
{% endif %}
{% endblock %}
settings.py
"""
Django settings for mysite project.
Generated by 'django-admin startproject' using Django 1.10.6.
For more information on this file, see
https://docs.djangoproject.com/en/1.10/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.10/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/1.10/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '71o%ek_%m5fg6ts(c_9_nj+m6eaf*&+jqgq^3ghih%26+opa12'
# 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',
'portfolio',
]
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 = 'mysite.urls'
# import os
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'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 = 'mysite.wsgi.application'
# Database
# https://docs.djangoproject.com/en/1.10/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/1.10/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/1.10/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC +3'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/
STATIC_URL = '/static/'
# STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)
# STATIC_ROOT = os.path.join(BASE_DIR, 'static_root')
所以它似乎正在寻找存在的portfolio / skill_list.html。
答案 0 :(得分:1)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR,'..', 'templates')],
'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',
],
},
},
答案 1 :(得分:0)
Django looks in the templates
directory for each app. Therefore your portfolio/skill_list.html
template should be in mysite/portfolio/templates/portfolio/skill_list.html
.