How to format django template code nicely with notepad++?

1,686 views
Skip to first unread message

mongoose

unread,
Feb 22, 2011, 9:55:21 AM2/22/11
to Django users
hi all,

I'm using notepad++ a lot and really missing a code formatter (vim
would be = to format).
Anyone know of anyway to format my html nicely? I've tried HTML Tidy
but it keeps adding a 20% where I have a space for example
"{{%20MEDIA_URL%20}}css/styles.css".

Bill Freeman

unread,
Feb 22, 2011, 10:23:21 AM2/22/11
to django...@googlegroups.com
And, certainly, replacing the %20 stuff is easy in python, should you
be happy with Tidy plus a post processing step. There are probably
even suitable functions in the http or urllib libraries that will
catch more than the %20s. You could even have the python tool run
Tidy for you, so that it looks like one step.

On Tue, Feb 22, 2011 at 10:20 AM, Bill Freeman <ke1...@gmail.com> wrote:
> You *could* use Tidy, then post process with a sed script to convert
> the '%20's to spaces.
>
> There may be comparable Windows tool, but if you want sed, you can
> install Cygwin.
>
> But if you install Cygwin, you could edit with vim.
>
> Since you're editing templates, you probably have python installed.
> If there isn't already a python based template reformatter, that
> sounds like an obvious project.  It would still be outside your
> editor, however.  I really want formatting aid inside my editor
> (spoiled emacs user).  Perhaps an extension to IDLE?

>> --
>> You received this message because you are subscribed to the Google Groups "Django users" group.
>> To post to this group, send email to django...@googlegroups.com.
>> To unsubscribe from this group, send email to django-users...@googlegroups.com.
>> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>>
>>
>

Bill Freeman

unread,
Feb 22, 2011, 10:20:32 AM2/22/11
to django...@googlegroups.com
You *could* use Tidy, then post process with a sed script to convert
the '%20's to spaces.

There may be comparable Windows tool, but if you want sed, you can
install Cygwin.

But if you install Cygwin, you could edit with vim.

Since you're editing templates, you probably have python installed.
If there isn't already a python based template reformatter, that
sounds like an obvious project. It would still be outside your
editor, however. I really want formatting aid inside my editor
(spoiled emacs user). Perhaps an extension to IDLE?

On Tue, Feb 22, 2011 at 9:55 AM, mongoose <darren...@gmail.com> wrote:

mongoose

unread,
Feb 22, 2011, 3:31:43 PM2/22/11
to Django users
want to get vim working with omnicomplete then perhaps i'll get into
it more.

I've added this to my vimrc file

filetype plugin on
set ofu=syntaxcomplete#Complete

when i try
:python print 'hello'
i get this error
"Could not load library python26.dll
The python library could not be loaded."

first of all i have python 2.7 installed. second how can i specify
where vim needs to look to find the dll?


On Feb 22, 5:20 pm, Bill Freeman <ke1g...@gmail.com> wrote:
> You *could* use Tidy, then post process with a sed script to convert
> the '%20's to spaces.
>
> There may be comparable Windows tool, but if you want sed, you can
> install Cygwin.
>
> But if you install Cygwin, you could edit with vim.
>
> Since you're editing templates, you probably have python installed.
> If there isn't already a python based template reformatter, that
> sounds like an obvious project.  It would still be outside your
> editor, however.  I really want formatting aid inside my editor
> (spoiled emacs user).  Perhaps an extension to IDLE?
>

Bill Freeman

unread,
Feb 22, 2011, 3:00:28 PM2/22/11
to django...@googlegroups.com
Except beware of using vi/vim to edit .py files since they are normally
configured to use tabs for indentation and to assume that a tab means
4 columns, whereas python (correct in the view of a really old timer)
takes them to mean 8 columns.

It is possible to configure at least vim to never insert tab characters
and to convert them to the right number of spaces for 8 columns on
reading a .py file. But that's a separate issue.

On Tue, Feb 22, 2011 at 2:20 PM, Brice Leroy <bbrri...@gmail.com> wrote:
> Learning VI is good for you and it makes you fast. Learning curve is steep,
> I agree, but the result is quite amazing. One other big advantage, you can
> easily work on any server through SSH.
>
> 2011/2/22 mongoose <darren...@gmail.com>
>>
>> I used vim for a while but the learning curve really is steep. so
>> steep that i'm more effecient with the old style editors. perhaps i'll
>> just do what i do in notepad++ then format it in vim. i'll keep
>> looking around for a nice formatter though.


>>
>> On Feb 22, 5:20 pm, Bill Freeman <ke1g...@gmail.com> wrote:

>> > You *could* use Tidy, then post process with a sed script to convert
>> > the '%20's to spaces.
>> >
>> > There may be comparable Windows tool, but if you want sed, you can
>> > install Cygwin.
>> >
>> > But if you install Cygwin, you could edit with vim.
>> >
>> > Since you're editing templates, you probably have python installed.
>> > If there isn't already a python based template reformatter, that
>> > sounds like an obvious project.  It would still be outside your
>> > editor, however.  I really want formatting aid inside my editor
>> > (spoiled emacs user).  Perhaps an extension to IDLE?
>> >

>> > On Tue, Feb 22, 2011 at 9:55 AM, mongoose <darrenma1...@gmail.com>


>> > wrote:
>> > > hi all,
>> >
>> > > I'm using notepad++ a lot and really missing a code formatter (vim
>> > > would be = to format).
>> > > Anyone know of anyway to format my html nicely? I've tried HTML Tidy
>> > > but it keeps adding a 20% where I have a space for example
>> > > "{{%20MEDIA_URL%20}}css/styles.css".
>> >
>> > > --
>> > > You received this message because you are subscribed to the Google
>> > > Groups "Django users" group.
>> > > To post to this group, send email to django...@googlegroups.com.
>> > > To unsubscribe from this group, send email to
>> > > django-users...@googlegroups.com.
>> > > For more options, visit this group
>> > > athttp://groups.google.com/group/django-users?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>
>
>

> --
> blog: http://www.debrice.com
> project: http://alpha.kaaloo.com http://alpha.djangogenerator.com
> linkedin: http://www.linkedin.com/in/bricepleroy

Bill Freeman

unread,
Feb 22, 2011, 3:56:31 PM2/22/11
to django...@googlegroups.com
what happens if you type:

python

at the Cygwin shell prompt?

And what does it say if you type:

which python

dele...@dudupay.com

unread,
Feb 22, 2011, 4:21:17 PM2/22/11
to django...@googlegroups.com
You might want to try Activestate Komodo Edit.
That's what I use and it's such a wonderful experience.
Regards.
Sent from my BlackBerry wireless device from MTN

Brice Leroy

unread,
Feb 22, 2011, 4:26:04 PM2/22/11
to django...@googlegroups.com
Might seam rude but you should try coding on linux. Some easy distribution like ubuntu. You can even install it in a virtual environment with virtual box.

Daniel Roseman

unread,
Feb 22, 2011, 4:28:37 PM2/22/11
to django...@googlegroups.com
On Tuesday, February 22, 2011 8:31:43 PM UTC, mongoose wrote:
want to get vim working with omnicomplete then perhaps i'll get into
it more.

I've added this to my vimrc file

filetype plugin on
set ofu=syntaxcomplete#Complete

when i try
:python print 'hello'
i get this error
"Could not load library python26.dll
The python library could not be loaded."

first of all i have python 2.7 installed. second how can i specify
where vim needs to look to find the dll?


You'll need to compile vim with Python support, if it doesn't already have it. vim doesn't use the installed Python, it has to be compiled in.

--
DR. 

dele...@dudupay.com

unread,
Feb 22, 2011, 4:42:21 PM2/22/11
to django...@googlegroups.com
The ssh thing, I agree. It works like magic. I'm however compelled to believe that the time you'd spend learning VI is enough to get you already developing django powered apps. My case study.

Sent from my BlackBerry wireless device from MTN


From: Brice Leroy <bbrri...@gmail.com>
Date: Tue, 22 Feb 2011 11:20:21 -0800
Cc: mongoose<darren...@gmail.com>
Subject: Re: How to format django template code nicely with notepad++?

Learning VI is good for you and it makes you fast. Learning curve is steep, I agree, but the result is quite amazing. One other big advantage, you can easily work on any server through SSH.

2011/2/22 mongoose <darren...@gmail.com>
I used vim for a while but the learning curve really is steep. so
steep that i'm more effecient with the old style editors. perhaps i'll
just do what i do in notepad++ then format it in vim. i'll keep
looking around for a nice formatter though.
On Feb 22, 5:20 pm, Bill Freeman <ke1g...@gmail.com> wrote:
> You *could* use Tidy, then post process with a sed script to convert
> the '%20's to spaces.
>
> There may be comparable Windows tool, but if you want sed, you can
> install Cygwin.
>
> But if you install Cygwin, you could edit with vim.
>
> Since you're editing templates, you probably have python installed.
> If there isn't already a python based template reformatter, that
> sounds like an obvious project.  It would still be outside your
> editor, however.  I really want formatting aid inside my editor
> (spoiled emacs user).  Perhaps an extension to IDLE?
>
> On Tue, Feb 22, 2011 at 9:55 AM, mongoose <darrenma1...@gmail.com> wrote:
> > hi all,
>
> > I'm using notepad++ a lot and really missing a code formatter (vim
> > would be = to format).
> > Anyone know of anyway to format my html nicely? I've tried HTML Tidy
> > but it keeps adding a 20% where I have a space for example
> > "{{%20MEDIA_URL%20}}css/styles.css".
>
> > --
> > You received this message because you are subscribed to the Google Groups "Django users" group.
> > To post to this group, send email to django...@googlegroups.com.
> > To unsubscribe from this group, send email to django-users...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Brice Leroy

unread,
Feb 22, 2011, 2:20:21 PM2/22/11
to django...@googlegroups.com, mongoose
Learning VI is good for you and it makes you fast. Learning curve is steep, I agree, but the result is quite amazing. One other big advantage, you can easily work on any server through SSH.

2011/2/22 mongoose <darren...@gmail.com>
I used vim for a while but the learning curve really is steep. so
steep that i'm more effecient with the old style editors. perhaps i'll
just do what i do in notepad++ then format it in vim. i'll keep
looking around for a nice formatter though.

On Feb 22, 5:20 pm, Bill Freeman <ke1g...@gmail.com> wrote:
> You *could* use Tidy, then post process with a sed script to convert
> the '%20's to spaces.
>
> There may be comparable Windows tool, but if you want sed, you can
> install Cygwin.
>
> But if you install Cygwin, you could edit with vim.
>
> Since you're editing templates, you probably have python installed.
> If there isn't already a python based template reformatter, that
> sounds like an obvious project.  It would still be outside your
> editor, however.  I really want formatting aid inside my editor
> (spoiled emacs user).  Perhaps an extension to IDLE?
>
> On Tue, Feb 22, 2011 at 9:55 AM, mongoose <darrenma1...@gmail.com> wrote:
> > hi all,
>
> > I'm using notepad++ a lot and really missing a code formatter (vim
> > would be = to format).
> > Anyone know of anyway to format my html nicely? I've tried HTML Tidy
> > but it keeps adding a 20% where I have a space for example
> > "{{%20MEDIA_URL%20}}css/styles.css".
>
> > --
> > You received this message because you are subscribed to the Google Groups "Django users" group.
> > To post to this group, send email to django...@googlegroups.com.
> > To unsubscribe from this group, send email to django-users...@googlegroups.com.
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

mongoose

unread,
Feb 22, 2011, 2:06:45 PM2/22/11
to Django users
I used vim for a while but the learning curve really is steep. so
steep that i'm more effecient with the old style editors. perhaps i'll
just do what i do in notepad++ then format it in vim. i'll keep
looking around for a nice formatter though.

On Feb 22, 5:20 pm, Bill Freeman <ke1g...@gmail.com> wrote:
> You *could* use Tidy, then post process with a sed script to convert
> the '%20's to spaces.
>
> There may be comparable Windows tool, but if you want sed, you can
> install Cygwin.
>
> But if you install Cygwin, you could edit with vim.
>
> Since you're editing templates, you probably have python installed.
> If there isn't already a python based template reformatter, that
> sounds like an obvious project.  It would still be outside your
> editor, however.  I really want formatting aid inside my editor
> (spoiled emacs user).  Perhaps an extension to IDLE?
>

Tom Evans

unread,
Feb 23, 2011, 4:51:18 AM2/23/11
to django...@googlegroups.com
On Tue, Feb 22, 2011 at 9:42 PM, <dele...@dudupay.com> wrote:
> The ssh thing, I agree. It works like magic. I'm however compelled to
> believe that the time you'd spend learning VI is enough to get you already
> developing django powered apps. My case study.
>

It takes about a month to get up to speed with vim, about a year to
become proficient and about three years to be fully comfortable. The
longer you use vim, the faster you get using it, and the more
productive you can be compared to users using mouse driven GUIs.
If you intend making a living out of knocking out 1's and 0's in a
specific order, it's wise to become fully acquainted with an editor
that is powerful and concise to use, and then never use anything but
that editor*.

From The Pragmatic Programmer [1]:

Use a Single Editor Well
The editor should be an extension of your hand; make sure your editor
is configurable, extensible, and programmable.

Cheers

Tom

[1] http://pragprog.com/the-pragmatic-programmer/extracts/tips

* It doesn't need to be vim, I also accept emacs.

Bill Freeman

unread,
Feb 23, 2011, 11:15:01 AM2/23/11
to django...@googlegroups.com
On Wed, Feb 23, 2011 at 4:51 AM, Tom Evans <teva...@googlemail.com> wrote:
...

> It takes about a month to get up to speed with vim, about a year to
> become proficient and about three years to be fully comfortable. The
> longer you use vim, the faster you get using it, and the more
> productive you can be compared to users using mouse driven GUIs.
> If you intend making a living out of knocking out 1's and 0's in a
> specific order, it's wise to become fully acquainted with an editor
> that is powerful and concise to use, and then never use anything but
> that editor*.
>
> From The Pragmatic Programmer [1]:
>
> Use a Single Editor Well
> The editor should be an extension of your hand; make sure your editor
> is configurable, extensible, and programmable.
>
> Cheers
>
> Tom

All good points.

I would caution, however, that not every *nix production environment
has vim. (Less and less true, but I still see them.)

They will, however, have vi. (And the ones that have vim typically have
vi as an alias.) If you can use vi, you can get by in vim. But some of
the vim features you learn aren't there, you could be frustrated. So, if
you are just learning vi[m] to make quick edits on your production boxes,
and you're not using it for anything else because you already have a
different favorite editor, I'd advise you to limit your self to the vi command
set, until it becomes habit to, for example, reach for the 'j' key rather than
the down arrow when you want to go to the next line (if you were in insert
mode, you obviously need to get out of it before using 'j').

[And few productions systems have emacs, my favorite, installed. For the
dyed in the wool emacs user, look at the tramp extension, though I haven't
found it totally satisfying. If your production box does have emacs, consider
ssh's -Y flag, to get emacs to pop up a window on your desktop, rather than
running inside the terminal. This requires at least the X client libraries on
the production box, and, due to bad packaging, sometimes requires X
server libraries, even though there is no display, and thus no need (or
ability) to run an X server. There's also NX, but ssh -Y is so easy to set
up.]

Bill

Tom Evans

unread,
Feb 23, 2011, 11:58:58 AM2/23/11
to django...@googlegroups.com
On Wed, Feb 23, 2011 at 4:15 PM, Bill Freeman <ke1...@gmail.com> wrote:
> All good points.
>
> I would caution, however, that not every *nix production environment
> has vim.  (Less and less true, but I still see them.)
>
> They will, however, have vi.  (And the ones that have vim typically have
> vi as an alias.)  If you can use vi, you can get by in vim.  But some of
> the vim features you learn aren't there, you could be frustrated.  So, if
> you are just learning vi[m] to make quick edits on your production boxes,
> and you're not using it for anything else because you already have a
> different favorite editor, I'd advise you to limit your self to the vi command
> set, until it becomes habit to, for example, reach for the 'j' key rather than
> the down arrow when you want to go to the next line (if you were in insert
> mode, you obviously need to get out of it before using 'j').

Eurgh, vi. I'm a FreeBSD man, so all boxes come with nvi, which is a
little more featured than plain old vi, but still more than unusable.
I *can* use vi, just like I *can* write C, fortunately 99.99% of the
time, I don't have to. In these days of TB disks, and GB of RAM, using
vi over vim seems sadistic to me, and so it gets installed on all
boxes as part of our basic package set.

>
> [And few productions systems have emacs, my favorite, installed.  For the
> dyed in the wool emacs user, look at the tramp extension, though I haven't
> found it totally satisfying.

Aargh, we're mortal enemies - I guess Eight Megs And Constantly
Swapping is no longer an insult I can use :)

This is where the pragmatic programmer rule comes in - tried emacs
once, didn't like it. Saw someone using vim like a wizard - code
magically appearing at a faster rate than any human can type, all
beautifully formatted and syntax highlighted - and was hooked.

From that point, 3 months of daily use till I wasn't repeatedly
referring to the cheat sheet, and felt completely comfortable about a
year after that.

Cheers

Tom

Bill Freeman

unread,
Feb 23, 2011, 12:38:33 PM2/23/11
to django...@googlegroups.com
On Wed, Feb 23, 2011 at 11:58 AM, Tom Evans <teva...@googlemail.com> wrote:
...
>
> Aargh, we're mortal enemies - I guess Eight Megs And Constantly
> Swapping is no longer an insult I can use :)

The last time I used a machine with fewer than 8Mb of RAM, emacs
was nowhere near that big. Besides, what are you running all those
other processes for? Emacs does it all.

> This is where the pragmatic programmer rule comes in - tried emacs
> once, didn't like it.

I've got to confess, it did take me a while to switch to emacs from teco.
(Of course, at the time emacs was implemented in teco.)

;^) - in case you couldn't tell.

Reply all
Reply to author
Forward
0 new messages