output_vars.py文件内容
from django.http import HttpResponse
from django.template import Template,Contextif name == "__main__":
print "Hello World";
def output(request):
t=Template("My name is{{lastname}}{{firstname}}");
c=Context({"firstname":"三","lastname":"张"});
t.render(c);
return HttpResponse(t);
urls.py内容
from django.conf.urls.defaults import *urlpatterns = patterns('',
(r'^outputvars/$','mysite.output_vars.output'),
)
在浏览器输入http://127.0.0.1:8000/outputvars/居然什么也不显示,网页源代码显示:
<Text Node: 'My name is'><Variable Node: lastname><Variable Node: firstname>
不知道怎么回事,是配置有问题,还是哪里写错了?刚刚学python.
问题补充
果然是这里错了,我看的不够仔细啊!谢谢小疯子!
呃,还有一个问题是我要把output_vars.py这个视图文件放到文件夹views中,那么需要改哪些东西,怎么改?
问题补充:
改成(r'^outputvars/$','mysite.views.output_vars.output')也不行,提示:
ViewDoesNotExist at /outputvars/
Could not import mysite.views.output_vars. Error was: No module named output_varsRequest Method: GET
Request URL: http://localhost:8000/outputvars/
Exception Type: ViewDoesNotExist
Exception Value: Could not import mysite.views.output_vars. Error was: No module named output_vars
Exception Location: D:\Python\Python2.6\lib\site-packages\django\core\urlresolvers.py in _get_callback, line 133
Python Executable: D:\Python\Python2.6\python.exe
Python Version: 2.6.0
Python Path: ['D:\Python\Python2.6\webapps\mysite', 'D:\Python\Python2.6\python26.zip', 'D:\Python\Python2.6\DLLs', 'D:\Python\Python2.6\lib', 'D:\Python\Python2.6\lib\plat-win', 'D:\Python\Python2.6\lib\lib-tk', 'D:\Python\Python2.6', 'D:\Python\Python2.6\lib\site-packages']
Server time: Wed, 29 Jul 2009 10:10:55 +0800