2

I'm having trouble with my python code. I think my using the right python structure but it keeps showing me (unexpected indent error)

class TopGamesPostPage(Handler):
    def get(self):
        self.render("topgamespost.html")

    def post(self):
        title = self.request.get('title')
        info = self.request.get('info')

        if title and info: --> unexpected indent error
            p = Post(parent = blog_key(), title = title, info=info)
            p.put()
            self.redirect('/topgames/%s' % str(p.key().id()))
        else:
            error = "subject and content, please!"
            self.render("topgamespost.html", title=title, info=info, error=error)
Christian Dean
  • 22,138
  • 7
  • 54
  • 87
  • 1
    Try an editor like Sublime. In Sublime, if you highlight all your code, you see dots for spaces and long dashes for tabs. If they're mixed up, it won't work. Sublime also has tools to convert to all tabs or all spaces. This happens often when copy/pasting code. – Brenden Petersen Oct 14 '17 at 05:27
  • I'm using VS 2017, and i have not mixed space in my file –  Oct 14 '17 at 05:55

2 Answers2

2

There could be a number of reasons such as mixing tabs and spaces, hidden unicode characters etc. Paste the portion of the code causing problem here. It will show you the exact problem.

Jayson Chacko
  • 2,388
  • 1
  • 11
  • 16
1

Since Python expects the whitespace in each indented line of the same level to be exactly the same, and the whitespace "lengths" look the same in your editor, it could be that you have a mix of tabs and spaces in your file.

Carol Ng
  • 575
  • 2
  • 11