I started working on "Django 1.0 Web Sit开发者_运维问答e Development" and have gotten my server to work, but when I'm editing my views.py file, I have a difficulty editing the python code in emacs.
The problem seems to be a line that contains the triple quotes ('''):
def main_page(request):
output = u'''
<html>
[more lines here]
</html>
''' % (
u'Django Bookmarks'
u'Welcome to Django Bookmarks',
u'Where you can store and share bookmarks!'
)
return HttpResponse(output)
Emacs identation gets all screwed up after the u''' line and thus I get errors when I try to load the page that is generated from this.
I've tried several modes (including a nxhtml mumamo mode), but so far I can get Emacs to recognize only python code or only html, but not both at the same time. Short of editing the file as raw text and manipulating the tabs myself, is there another way/
Take the hint.
You're doing it wrong. Get to the templates business in chapter 3 before even thinking about tools to support what you're doing.
Stop trying to embed HTML in your view functions and you'll find that emacs is no longer confused. Move as quickly as possible to the next chapter. Stop messing with emacs and get going on learning Django. Move further forward in the book.
But HTML in template files which are almost pure HTML with a few extra {{variable}}
and {% tag %}
things thrown around.
You don't have an "emacs formatting" problem.
You have a "using Django incorrectly" problem.
精彩评论