Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Nov. 18, 2005 09:12:51

David A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


After watching the TurboGears 20 minute wiki screencast today, I figured I'd try to build the equivalent code in Django to see what it's like.It took me more than 20 minutes, but since this is my first non-tutorial Django app, I'm ok with that.If anyone is interested, I've put it up at:http://da.textdriven.com:8027/sydney/browser/trunk/wiki/Specifically, I'd love feedback on the views (http://da.textdriven.com:8027/sydney/file/trunk/wiki/apps/pages/views.py) and the template (http://da.textdriven.com:8027/sydney/file/trunk/wiki/templates/pages/page.html).  Everything else seems relatively straightforward, although I may be doing Bad Things with the urls too (http://da.textdriven.com:8027/sydney/file/trunk/wiki/urls.py).Note that unlike the TurboGears's use of MochiKit to convert JSON to DOM, I used the trivial ahah.js code from the microformats folks (http://www.microformats.org/wiki/rest/ahah) to do the Ajax operation.  Only one line of JS even though there is a maybe a bit more stuff going over the wire.About 70 lines of Python, 23 lines of HTML.What I liked about the process:  * the runserver make interactive work really easy.  * the tracebacks are very helpfulStumbling blocks:  * figuring out that I had to do "import
django.contrib.markup.templatetags.markup" to get the markup filters
registered was harder than it should have been.  * understanding that the redirects involved in adding trailing /'s threw away POST data took me a while to figure out  * I was stumped by the fact that I had to setup another web server to serve static files.  It'd be nice if it was possible to serve static files with the development server.  I'd consider sending in a patch if someone could throw suggestions my way on what approach would work best  (or maybe it actually _is_ supported, I just didn't find out how!).Overall, quite an enjoyable experience!--david

Offline

#2 Nov. 18, 2005 10:01:15

Kenneth G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


On Friday 18 Nov 2005 2:42 pm, David Ascher wrote:
> and the template (
>http://da.textdriven.com:8027/sydney/file/trunk/wiki/templates/pages/>page.html).

where is the base template?

--
regards
kghttp://www.livejournal.com/users/lawgontally ho!http://avsap.org.inಇಂಡ್ಲಿನಕ್ಸ வாழ்க!

Offline

#3 Nov. 18, 2005 10:58:26

Simon W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


On 18 Nov 2005, at 09:12, David Ascher wrote:Specifically, I'd love feedback on the views ( http://da.textdriven.com:8027/sydney/file/trunk/wiki/apps/pages/views.py)and the template (http://da.textdriven.com:8027/sydney/file/trunk/wiki/templates/pages/page.htmlYou should do this in the template: Replace<textarea id="data" name="data" rows="10" cols="60">{{page.data}}</textarea>With<textarea id="data" name="data" rows="10" cols="60">{{page.data|escape}}</textarea>Great feedback on the problems you can in to - we should fix those!

Offline

#4 Nov. 18, 2005 12:00:11

h.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


> * I was stumped by the fact that I had to setup another web server to serve
>static files. It'd be nice if it was possible to serve static files with the
>development server. I'd consider sending in a patch if someone could throw
>suggestions my way on what approach would work best (or maybe it actually
>_is_ supported, I just didn't find out how!).

There is a django.views.static module that has a "serve" view function
that can be used for serving static files from a directory. So no need
to send in a patch ;-)

(I think this static view should be listed more prominently in the
documentation and tutorial, even though it's not meant to be used for
production use - the how-to-serve-static-files question is quite common
with newbies, and all of them want to write their own ;-) )

bye, Georg

Offline

#5 Nov. 18, 2005 14:12:47

Simon W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


On 18 Nov 2005, at 11:59, hugo wrote:(I think this static view should be listed more prominently in the
documentation and tutorial, even though it's not meant to be used forproduction use - the how-to-serve-static-files question is quitecommonwith newbies, and all of them want to write their own ;-) )I entirely agree. I think we should encourage people to run Django asinefficiently as they like during development, then have all of thepreaching about separate servers for static files etc in thedeployment documentation.Cheers,

Simon

Offline

#6 Nov. 18, 2005 14:34:55

Bryan M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


On 11/18/05, David Ascher <> wrote:
> After watching the TurboGears 20 minute wiki screencast today, I figured I'd
> try to build the equivalent code in Django to see what it's like.
>
> It took me more than 20 minutes, but since this is my first non-tutorial
> Django app, I'm ok with that.
>
> If anyone is interested, I've put it up at:
>http://da.textdriven.com:8027/sydney/browser/trunk/wiki/>
> Specifically, I'd love feedback on the views (
>http://da.textdriven.com:8027/sydney/file/trunk/wiki/apps/pages/views.py)
> and the template (
>http://da.textdriven.com:8027/sydney/file/trunk/wiki/templates/pages/page.html).
> Everything else seems relatively straightforward, although I may be doing
> Bad Things with the urls too (
>http://da.textdriven.com:8027/sydney/file/trunk/wiki/urls.py).
>
> Note that unlike the TurboGears's use of MochiKit to convert JSON to DOM, I
> used the trivial ahah.js code from the microformats folks (
>http://www.microformats.org/wiki/rest/ahah) to do the Ajax
> operation. Only one line of JS even though there is a maybe a bit more
> stuff going over the wire.
>
> About 70 lines of Python, 23 lines of HTML.

That's awesome! Thanks for sharing. That does a good job, for me at
least, showing off a lot of the little nicities django has to offer,
like the generic view to do the page list, and the template filters.
You should write this up and make a movie out of it! :-)

Bryan

Offline

#7 Nov. 18, 2005 15:10:04

Jacob K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


On Nov 18, 2005, at 3:12 AM, David Ascher wrote:After watching the TurboGears 20 minute wiki screencast today, Ifigured I'dtry to build the equivalent code in Django to see what it's like.Very cool -- I'm glad you had fun!Stumbling blocks:
* figuring out that I had to do "import
django.contrib.markup.templatetags.markup" to get the markup filters
registered was harder than it should have been.Actually, that's what the {% load %} tag is for. Assuming you've got"django.contrib.markup" in your INSTALLED_APPS, a "{% load markup %}"will load that template tag library for your use. This is documented(http://www.djangoproject.com/documentation/templates/#custom-tag-and-filter-libraries), but perhaps not as well as it might be.* understanding that the redirects involved in adding trailing /'sthrewaway POST data took me a while to figure outThis isn't Django, FYI; there's no way to issue a redirect andinclude POST data. I'll agree that this is a stumbler, but think ofit as doing are part to ensure people use clean URLs :)* I was stumped by the fact that I had to setup another web serverto servestatic files. It'd be nice if it was possible to serve static fileswith thedevelopment server. I'd consider sending in a patch if someonecould throwsuggestions my way on what approach would work best (or maybe itactually_is_ supported, I just didn't find out how!).As others have pointed out, the view "django.views.static.serve" willdo this. The reason we don't advertise this view too much is thatit's *very* unsuited for production use and we don't want peoplerelying on it. Still, we should document it somewhere along with abig yummy warning.Jacob

Offline

#8 Nov. 18, 2005 15:35:46

Robert W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


David Ascher wrote:
> Stumbling blocks:
> * figuring out that I had to do "import
> django.contrib.markup.templatetags.markup" to get the markup filters
> registered was harder than it should have been.
Did {% load markup %} not work? Maybe this tag needs to be pointed out
more prominently - it is at "Custom tag and filter libraries" inhttp://www.djangoproject.com/documentation/templates/.

> * understanding that the redirects involved in adding trailing /'s threw
> away POST data took me a while to figure out
Hm, maybe when DEBUG is on, CommonMiddleware should put up an
interstitial page to tell the developer what is happening? It does seem
to bite a lot of people.

> * I was stumped by the fact that I had to setup another web server to serve
> static files. It'd be nice if it was possible to serve static files with the
> development server. I'd consider sending in a patch if someone could throw
> suggestions my way on what approach would work best (or maybe it actually
> _is_ supported, I just didn't find out how!).
I've been thinking about this as well - maybe we should automatically
register /<appname>/media/ to use the static view to load out of
<appdir>/media in the development server.

So we could have a dictionary in settings,
MEDIA_PREFIXES = {
'wiki.apps.pages' : '/pages/media/' ,
'django.contrib.admin': 'http://media.example.com/admin/'
}

To override the default when not running in the dev server.

Then a template tag like {% media_prefix app %} which would rely on an
'app' variable in the context being the dot name of the app :
wiki.apps.pages. Maybe this could be done easily with DjangoContext, not
sure.

This would (I think) work obviously in the runserver, and be easily
extensible to other deployment scenarios.

Offline

#9 Nov. 18, 2005 15:52:45

Simon W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


On 18 Nov 2005, at 15:26, Robert Wittams wrote:Hm, maybe when DEBUG is on, CommonMiddleware should put up aninterstitial page to tell the developer what is happening? It doesseemto bite a lot of people.Alternatively, we could just have CommonMiddleware throw a deliberateserver error if a POST is made to a IRL that doesn't have a trailingslash. That should make things abundantly clear :) POSTing to a URLthat CommonMiddleware wants to redirect is most definitely a bug inan application, and should be treated as such. The redirect plainshouldn't happen.Cheers,

Simon

Offline

#10 Nov. 18, 2005 17:46:25

David A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

20 minute wiki, sortof.


On 11/18/05,Simon Willison<> wrote:Alternatively, we could just have CommonMiddleware throw a deliberateserver error if a POST is made to a IRL that doesn't have a trailingslash. That should make things abundantly clear :) POSTing to a URLthat CommonMiddleware wants to redirect is most definitely a bug inan application, and should be treated as such. The redirect plainshouldn't happen.Makes sense to me.  Shouldn't even break old code, assuming they care what's in the POST data ="">kb: there is no base template -- was that a hint that I should use template inheritance instead of an if/else/endif?Thanks for the pointers to django.views.static and {% load markup %}.  I'd clearly missed those.re: load markup, I suggest a comment at the top of the markup.py file telling people to read up on the load markup docs.  Also, what's the rationale for failing silently if the required modules aren't installed?re: django.views.static: I suspect that given the number of times I saw my question asked and answered with "django doesnt' do that" in the IRC logs, that it may qualify as a FAQ.Cheers,--david

Offline

Board footer

Moderator control

Enjoy the 22nd of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support