V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
tjxiter
V2EX  ›  Python

django 搭建 blog 出错求指点

  •  
  •   tjxiter · 2015-09-08 17:24:04 +08:00 · 3202 次点击
    这是一个创建于 3142 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我正在仿 http://andrew-liu.gitbooks.io/django-blog/content/template.html 来搭建博客。

    出现错误,一时查不出来。求大神指点。

    article/view.py
    1 from datetime import datetime
    2
    3 from django.shortcuts import render
    4 from django.http.response import HttpResponse
    5
    6 from article.models import Article
    7
    8
    9 def home (request ):
    10 post_list = Article.objects.all ()
    11 return render (request. 'home.html', {'post_list': post_list,})
    12
    13
    14 def detail (request, my_args ):
    15 post = Article.objects.all ()[int (my_args )]
    16 str = ("title=%s, category=%s, date_time=%s, content=%s"
    17 % (post.title, post.category, post.date_time, post.content ))
    18 return HttpResponse (str )

    网页端报错如下:
    invalid syntax (views.py, line 11 )
    Request Method: GET
    Request URL: http://127.0.0.1:8000/
    Django Version: 1.8.4
    Exception Type: SyntaxError
    Exception Value:
    invalid syntax (views.py, line 11 )
    Exception Location: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py in import_module, line 37
    Python Executable: /Users/tjx/EVN2.7/bin/python
    Python Version: 2.7.10


    就是说 11 行有语法错误啊。我看了 11 行, render 的那三个参数都 ok 。怎么就语法错误了?
    8 条回复    2015-09-09 17:48:27 +08:00
    tjxiter
        1
    tjxiter  
    OP
       2015-09-08 17:27:22 +08:00
    Mac 下得 virtualenv

    python:2.7.10
    django:1.8.4
    864000951
        2
    864000951  
       2015-09-08 17:29:51 +08:00
    11 return render (request. 'home.html', {'post_list': post_list,})
    invalid syntax (views.py, line 11 )

    request. 'home.html'
    tjxiter
        3
    tjxiter  
    OP
       2015-09-08 17:34:06 +08:00
    @864000951 多谢。。。

    知道怎么删帖吗? 弱死了。
    tjxiter
        4
    tjxiter  
    OP
       2015-09-08 17:34:45 +08:00
    把 vim 的字体调大了点。
    Cynic222
        5
    Cynic222  
       2015-09-08 17:41:18 +08:00
    你需要 pycharm
    tjxiter
        6
    tjxiter  
    OP
       2015-09-08 21:46:54 +08:00
    @Cynic222 用 vim 一年多。正在下载 pycharm ,了解了下,好强大的样子。
    junzki
        7
    junzki  
       2015-09-09 10:36:15 +08:00
    SyntaxError 这种问题就睁大眼睛仔细读代码吧!看看是不是一时疏忽打错了什么。而且错误提示已经指示了具体的行号~
    tjxiter
        8
    tjxiter  
    OP
       2015-09-09 17:48:27 +08:00
    @junzki 大神所言即是。语法错误就一个一个字符读。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4128 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:20 · PVG 13:20 · LAX 22:20 · JFK 01:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.