python django应用程序-并非所有参数都在字符串格式化期间转换

python django应用程序-并非所有参数都在字符串格式化期间转换,python,django,django-models,django-templates,django-views,Python,Django,Django Models,Django Templates,Django Views,这是python django的初始教程。文章是我的应用程序名。django_ètes是我的项目。将项目加载到服务器/hello/I时,出现以下错误: 环境: 请求方法:获取请求URL:servername/hello/ Django版本:1.6.2 Python版本:2.7.5已安装的应用程序: ('django.contrib.admin'、'django.contrib.auth', 'django.contrib.contenttypes','django.contrib.session

这是python django的初始教程。文章是我的应用程序名。django_ètes是我的项目。将项目加载到服务器/hello/I时,出现以下错误:

环境:

请求方法:获取请求URL:servername/hello/

Django版本:1.6.2 Python版本:2.7.5已安装的应用程序: ('django.contrib.admin'、'django.contrib.auth', 'django.contrib.contenttypes','django.contrib.sessions', 'django.contrib.messages'、'django.contrib.staticfiles'、'article') 已安装的中间件: ('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.xframeoptions中间件')

回溯:文件 中的“/usr/lib/python2.7/site packages/django/core/handlers/base.py” 得到你的回应 114response=hello中的wrapped_callback(请求,*callback_args,**callback_kwargs)文件“/cygdrive/d/fraservalley/django/django_tes/article/views.py” 10name=“迈克”

异常类型:TypeError at/hello/异常值:并非全部 字符串格式化期间转换的参数

我对python和django完全陌生。我可以理解在views.py中%s对应于名称字符串,那么为什么会出现错误

谁能帮忙吗


文章文件夹中的views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
from models import Article
# Create your views here.
#views are representations of what the user might see

def hello(request):
   name = "Mike"
   html = "<html><body>Hi %s this seem to work!</body></html>" % name
   return HttpResponse(html)
'''
def hello_template(request):
   name = "Mike"
   t = get_template('hello.html')
   html = t.render(Context({'name': name}))
   return HttpResponse(html)
'''
from django.conf.urls import patterns, include, url
from article import views
#from django.contrib import admin
#admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'django_tes.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^hello/$','article.views.hello'),
    #url(r'^hello_template/$','article.views.hello_template'),
    #url(r'^admin/', include(admin.site.urls)),
)
from django.db import models

# Create your models here.

class Article(models.Model): #helps to create representation of data
   title = models.CharField(max_length=200)
   body = models.TextField()
   pub_date = models.DateTimeField('date published')
   likes = models.IntegerField()

   def __unicode__(self):
      return self.title
"""
Django settings for django_tes project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_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',
    'article',
)

MIDDLEWARE_CLASSES = (
    '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 = 'django_tes.urls'

WSGI_APPLICATION = 'django_tes.wsgi.application'

TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'D:/fraservalley/django/django_tes/storage.db',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/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/1.6/howto/static-files/

STATIC_URL = '/static/'
django_tes文件夹中的models.py

from django.shortcuts import render
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
from models import Article
# Create your views here.
#views are representations of what the user might see

def hello(request):
   name = "Mike"
   html = "<html><body>Hi %s this seem to work!</body></html>" % name
   return HttpResponse(html)
'''
def hello_template(request):
   name = "Mike"
   t = get_template('hello.html')
   html = t.render(Context({'name': name}))
   return HttpResponse(html)
'''
from django.conf.urls import patterns, include, url
from article import views
#from django.contrib import admin
#admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'django_tes.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^hello/$','article.views.hello'),
    #url(r'^hello_template/$','article.views.hello_template'),
    #url(r'^admin/', include(admin.site.urls)),
)
from django.db import models

# Create your models here.

class Article(models.Model): #helps to create representation of data
   title = models.CharField(max_length=200)
   body = models.TextField()
   pub_date = models.DateTimeField('date published')
   likes = models.IntegerField()

   def __unicode__(self):
      return self.title
"""
Django settings for django_tes project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_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',
    'article',
)

MIDDLEWARE_CLASSES = (
    '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 = 'django_tes.urls'

WSGI_APPLICATION = 'django_tes.wsgi.application'

TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'D:/fraservalley/django/django_tes/storage.db',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/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/1.6/howto/static-files/

STATIC_URL = '/static/'
django_tes文件夹中的settings.py

from django.shortcuts import render
from django.http import HttpResponse
from django.template.loader import get_template
from django.template import Context
from models import Article
# Create your views here.
#views are representations of what the user might see

def hello(request):
   name = "Mike"
   html = "<html><body>Hi %s this seem to work!</body></html>" % name
   return HttpResponse(html)
'''
def hello_template(request):
   name = "Mike"
   t = get_template('hello.html')
   html = t.render(Context({'name': name}))
   return HttpResponse(html)
'''
from django.conf.urls import patterns, include, url
from article import views
#from django.contrib import admin
#admin.autodiscover()

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'django_tes.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^hello/$','article.views.hello'),
    #url(r'^hello_template/$','article.views.hello_template'),
    #url(r'^admin/', include(admin.site.urls)),
)
from django.db import models

# Create your models here.

class Article(models.Model): #helps to create representation of data
   title = models.CharField(max_length=200)
   body = models.TextField()
   pub_date = models.DateTimeField('date published')
   likes = models.IntegerField()

   def __unicode__(self):
      return self.title
"""
Django settings for django_tes project.

For more information on this file, see
https://docs.djangoproject.com/en/1.6/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_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',
    'article',
)

MIDDLEWARE_CLASSES = (
    '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 = 'django_tes.urls'

WSGI_APPLICATION = 'django_tes.wsgi.application'

TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)

# Database
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'D:/fraservalley/django/django_tes/storage.db',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/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/1.6/howto/static-files/

STATIC_URL = '/static/'

另外,请包括整个堆栈跟踪?@warunsl添加了堆栈跟踪错误与
html
变量声明中使用的字符串格式有关。你能用
html=“Hi{}这似乎有效!”替换它吗?格式化(名称)
并检查?@warunsl该力有效你能试试
html=“Hi%s这似乎有效!”%(名称)