python django application - 不是在字符串格式化过程中转换的所有参数

时间:2014-04-02 23:14:29

标签: python django django-models django-templates django-views

这是python django的初始教程。文章是我的应用名称。 django_tes是我的项目。当我将项目加载到server / hello /时,我收到以下错误:

  

环境:

     

请求方法:GET请求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.XFrameOptionsMiddleware')

     

回溯:文件   “/usr/lib/python2.7/site-packages/django/core/handlers/base.py”in   get_response     114. response = wrapped_callback(request,* callback_args,** callback_kwargs)文件“/cygdrive/d/fraservalley/django/django_tes/article/views.py”你好     10. name =“Mike”

     

异常类型:/ hello / Exception中的TypeError值:不是全部   字符串格式化期间转换的参数

我对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)
'''
来自django_tes文件夹的

urls.py

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)),
)
来自django_tes文件夹的

models.py

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_tes文件夹的

settings.py

"""
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/'

0 个答案:

没有答案