- 论坛徽章:
- 6
|
本帖最后由 jcdiy0601 于 2015-08-19 10:10 编辑
我是按照步骤一步步走的,部分代码如下
app名为web
views文件- from django.shortcuts import render
- from django.shortcuts import render_to_response
- from django.http.response import HttpResponse
- from django.core.context_processors import request
- from models import Asset
- def AssetList(request):
- asset_list = Asset.objects.all()
- result = render_to_response('assetlist.html',{'data':asset_list,'user':'jiachen'})
- return result
复制代码 模板文件assetlist.html- {% load test %}
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <link type="text/css" rel="stylesheet" href="js/common.js">
- <title>assetlist</title>
- </head>
- <body>
- <h1>{{ user|upper }}</h1>
- <table border='1'>
-
- {% for item in data %}
- <tr>
- <td>{{item.id}}</td>
- <td>{{% a item.id %}}</td>
- <td>{{item.name}}</td>
- <td>{{item.create_date|date:"Y-m-d H:i:s"}}</td>
- <td>{{item.update_date|date:"Y-m-d H:i:s"}}</td>
- </tr>
- {% endfor %}
-
- {% if user %}
- <h2>真</h2>
- {% else %}
- <h2>假</h2>
- {% endif %}
-
- {% ifequal user 'alex' %}
- <h2>alex</h2>
- {% else %}
- <h2>feialex</h2>
- {% endifequal %}
- </table>
- </body>
- </html>
复制代码 app下建立templatetags包,并在其下面建立test.py文件,内容如下- #!/usr/bin/env python
- #_*_ coding:utf-8 _*_
- from django import template
- from django.utils.safestring import mark_safe
- from django.template.base import resolve_variable, Node, TemplateSyntaxError
-
- register = template.Library()
-
- @register.simple_tag
- def a(v1):
- result = v1*1000
- return result
复制代码 报错信息如下- TemplateSyntaxError at /web/assetlist/
- Could not parse the remainder: '% a item.id %' from '% a item.id %'
- Request Method: GET
- Request URL: http://127.0.0.1:8000/web/assetlist/
- Django Version: 1.6.5
- Exception Type: TemplateSyntaxError
- Exception Value:
- Could not parse the remainder: '% a item.id %' from '% a item.id %'
- Exception Location: C:\Python27\lib\site-packages\django\template\base.py in __init__, line 577
- Python Executable: C:\Python27\python.exe
- Python Version: 2.7.6
- Python Path:
- ['E:\\eclipse\\oldboy08day11',
- 'E:\\eclipse\\oldboy08day11',
- 'C:\\Python27\\DLLs',
- 'C:\\Python27\\lib',
- 'C:\\Python27\\lib\\lib-tk',
- 'C:\\Python27',
- 'C:\\Python27\\lib\\site-packages',
- 'C:\\Windows\\system32\\python27.zip',
- 'C:\\Python27\\lib\\plat-win']
- Server time: 星期三, 19 八月 2015 09:28:51 +0800
复制代码 |
|