Newbie: Help to understand string handling

1 view
Skip to first unread message

phoebebright

unread,
Jan 6, 2009, 3:14:16 PM1/6/09
to Django users
As a newbie to both python and django (ex PHP) I am not clear on when
I can use python functions and when I can't.

I want to do some simple string handling in a view, search and replace
for example, but can't find anything in the documentation. I assume
this means that I can use python string handling?

Alex Koshelev

unread,
Jan 6, 2009, 3:18:46 PM1/6/09
to django...@googlegroups.com
Yes. Django is just Python

phoebebright

unread,
Jan 6, 2009, 4:46:55 PM1/6/09
to Django users
Thanks for your response. Do you think a working knowledge of python
is essential for django then? And do I import modules the same in
django and python? Are there any python things you can't do in
django?



On Jan 6, 8:18 pm, "Alex Koshelev" <daeva...@gmail.com> wrote:
> Yes. Django is just Python
>

Jeff Anderson

unread,
Jan 6, 2009, 4:49:14 PM1/6/09
to django...@googlegroups.com
phoebebright wrote:
> Thanks for your response. Do you think a working knowledge of python
> is essential for django then? And do I import modules the same in
> django and python? Are there any python things you can't do in
> django?
>
Django *is* Python. In fact, Django is only a Python library. It is not
its own language.

signature.asc

Malinka Rellikwodahs

unread,
Jan 6, 2009, 4:51:39 PM1/6/09
to django...@googlegroups.com
On Tue, Jan 6, 2009 at 16:49, Jeff Anderson <jeff...@programmerq.net> wrote:
> phoebebright wrote:
>> Thanks for your response. Do you think a working knowledge of python
>> is essential for django then? And do I import modules the same in
>> django and python? Are there any python things you can't do in
>> django?

yes you should be able to in django do anything you can do in python

>>
> Django *is* Python. In fact, Django is only a Python library. It is not
> its own language.

excluding the template language obviously that isn't python

phoebebright

unread,
Jan 6, 2009, 6:03:22 PM1/6/09
to Django users
Thanks for that clarification. I am finding that a lot of assumptions
are made in the documentation about previous knowledge. The
documentation can appear very confusing until you understand the
background, then it magically becomes blindingly obvious and helpful!
I must write down more of these moments of clarification!


Maybe starting a collection of seemingly obvious statements would be
helpful for newbies:
- django is a module for python, so a basic knowledge of python is
required, although much can be learned by looking at examples and
reading the django documentation.
- django includes a templating language that has a limited set of
commands, so python code will not work there.
- unlike php, your django code can be anywhere on the server and
apache directives (right term) are used to redirect http requests to
your urls.py and from there to the rest of your programs.
- the apache directives may be in the httpd.conf file or vhost.conf
file or other include files. It just depends how your server is
setup.
- building querysets. If you want to add lots of filters in seperate
lines. eg. if x: filter on a, if y: filter on b, etc. then start by
selecting all into a new queryset and then build up additional filters
on the new queryset.

query=Car.objects.all()

if request.GET.get('transmission','Any') != "Any":
query=query.filter(transmission=request.GET.get
('transmission','Any'))
if request.GET.get('fuels','Any') != "Any":
query=query.filter(fuel_type=request.GET.get('fuels','Any'))
if request.GET.get('bodies','Any') != "Any":
query=query.filter(body_type=request.GET.get('bodies','Any'))

etc...




On Jan 6, 9:51 pm, "Malinka Rellikwodahs" <aelmali...@gmail.com>
wrote:

bruno desthuilliers

unread,
Jan 7, 2009, 4:55:32 AM1/7/09
to Django users
On 6 jan, 22:46, phoebebright <phoebebri...@spamcop.net> wrote:
> Thanks for your response. Do you think a working knowledge of python
> is essential for django then?

Obviously, yes !-)

That's just like asking if a working knowledge of Java is essential
for Strut, or if a working knowledge of PHP is essential for the Zend
Framework, or if a working knowledge of Ruby is essential for Ruby On
Rails (etc, insert your favorite language/web framework pair here...).

bruno desthuilliers

unread,
Jan 7, 2009, 5:26:06 AM1/7/09
to Django users
On 7 jan, 00:03, phoebebright <phoebebri...@spamcop.net> wrote:
> Thanks for that clarification. I am finding that a lot of assumptions
> are made in the documentation about previous knowledge.

Indeed. It is assumed that the reader knows at least a couple things
about the web, programming, HTML, and the HTTP protocol !-)

> Maybe starting a collection of seemingly obvious statements would be
> helpful for newbies:
> - django is a module for python, so a basic knowledge of python is
> required,

Go to the project's home page. The first line of text contains the
brand (and main menu). The fifth line - which is the first _effective_
content of the page - says :
"Django is a high-level Python Web framework"

I may be a bit biased here, but as far as I'm concerned, this is
obvious enough.

> - django includes a templating language that has a limited

s/limited/extensible/

> set of
> commands, so python code will not work there.

Still on the project's home page:
"""
Template system

Use Django's powerful, extensible and designer-friendly template
language to separate design, content and Python code.
"""

Note that you have two strong hints there:
1/ python code
2/ separate

If that's not enough, following the 'template language' link, you land
on a documentation page that makes the whole point very clear:

"""
If you have a background in programming, or if you’re used to
languages like PHP which mix programming code directly into HTML,
you’ll want to bear in mind that the Django template system is not
simply Python embedded into HTML. This is by design: the template
system is meant to express presentation, not program logic.

The Django template system provides tags which function similarly to
some programming constructs – an if tag for boolean tests, a for tag
for looping, etc. – but these are not simply executed as the
corresponding Python code, and the template system will not execute
arbitrary Python expressions
"""


(snip other already documented things).

Now I don't mean there's no room for improvement, but what, you just
can't stack everything on the home page, can you ?-)

Reply all
Reply to author
Forward
0 new messages