Py学习  »  问与答

新手。。。出了错误求大神解答!

455813474 • 9 年前 • 7299 次点击  

这是views.py

#coding=utf-8
from django.shortcuts import render
from django.http import HttpResponse
import datetime
import time

def hello(req):
    now= datetime.datetime.now()

    html="<html><body>hello world! It is now %s.</body></html>"% now


    return HttpResponse(html)

def a(req):
    now=time.strftime("H%:M%:S%")
    date=time.strftime("d%/m%/Y%")
    rep = "the time"+now+"the date"+date
    return HttpResponse(rep)

这是urls.py

from django.conf.urls import patterns, include, url
from django.contrib import admin
from hello_world.views import hello,a

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'mysite.views.home', name='home'),
    # url(r'^blog/', include('blog.urls')),
    url(r'^admin/', include(admin.site.urls)),

    url(r'^hello/$',hello),
    url(r'^a/$',a),

)

以下是输到浏览器中的错误

ValueError at /a/

Invalid format string

Request Method:     GET
Request URL:    http://127.0.0.1:8000/a/
Django Version:     1.7.1
Exception Type:     ValueError
Exception Value:

Invalid format string

Exception Location:     D:\pycharm project\mysite\hello_world\views.py in a, line 16
Python Executable:  D:\Python\python.exe
Python Version:     3.4.2
Python Path:

['D:\\pycharm project\\mysite',
 'D:\\Python\\lib\\site-packages\\django-1.7.1-py3.4.egg',
 'D:\\pycharm project\\mysite',
 'C:\\Windows\\system32\\python34.zip',
 'D:\\Python\\DLLs',
 'D:\\Python\\lib',
 'D:\\Python',
 'D:\\Python\\lib\\site-packages']

Server time:    Thu, 4 Dec 2014 19:02:34 +0800
Traceback Switch to copy-and-paste view

    D:\Python\lib\site-packages\django-1.7.1-py3.4.egg\django\core\handlers\base.py in get_response

                            response = wrapped_callback(request, *callback_args, **callback_kwargs)

        ...
    ▶ Local vars
    D:\pycharm project\mysite\hello_world\views.py in a

            now=time.strftime("H%:M%:S%")

        ...
    ▶ Local vars
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/817
 
7299 次点击  
文章 [ 11 ]  |  最新文章 9 年前