Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Form submissions now work (character encoding is assumed to be utf8 t…
…hough, which may cause problems some time) - new example_forms.py demonstrates them
- Loading branch information
Simon Willison
committed
May 12, 2009
1 parent
3349d37
commit 780b498
Showing
4 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import djng | ||
|
||
def index(request): | ||
return djng.Response(""" | ||
<h1>Forms demo</h1> | ||
<form action="/search/" method="get"> | ||
<p> | ||
<input type="search" name="q"> | ||
<input type="submit" value="Search"> | ||
</p> | ||
</form> | ||
<form action="/submit/" method="post"> | ||
<p><textarea name="text" rows="5" cols="30"></textarea></p> | ||
<p><input type="submit" value="Capitalise text"></p> | ||
</form> | ||
""") | ||
|
||
def search(request): | ||
return djng.Response( | ||
"This page would search for %s" % djng.escape( | ||
request.GET.get('q', 'no-search-term') | ||
) | ||
) | ||
|
||
def submit(request): | ||
text = request.POST.get('text', 'no-text') | ||
return djng.Response(djng.escape(text.upper())) | ||
|
||
app = djng.Router( | ||
(r'^$', index), | ||
(r'^search/$', search), | ||
(r'^submit/$', submit), | ||
) | ||
|
||
if __name__ == '__main__': | ||
djng.serve(app, '0.0.0.0', 8888) |