Getting Started With Python and Django - python

I am newbie to the Django framework. I want to learn it and use it to develop applications. I am new to python. To learn Django, do I need knowledge of python and design patterns?
I don't know whether I should learn the design patterns, e.g. MVC, and think about writing applications or instead start to learn the language by writing complex web applications. Your suggestions are welcome.

I'd suggest learning the basics of Python and at least the MVC design pattern first.
From there, yes, go ahead and starting creating a project in Django, it's the best way to learn Django.
As far as "python fundamentals" that means the obvious basic syntax and keywords. From there, it's more important that you understand "programming in general" especially the Object-oriented programming paradigm.

Jump right in to Django. You can do it, and learn as you go. Djangobook will teach you the foundations of Django to start building apps.
One of thing to keep in mind as far as Python itself goes is using PEP8 to style your code, it'll make it easier down the road when others are looking at your code, whether for help or when working on projects.
#S.Lott is right, foundations are important
However, I think it's possible to learn the foundation while building an actual project/app and having some fun/gaining some experience at the same time.
(note: such as the provided tutorials from django, like the poll app)
Edit: I'd like to point out that in the comments below, I no longer support my answer for this particular situation. If the person is experienced with programming and language fundamentals, to me they have the knowledge necessary and the language is merely the tool they use. If that is the case I don't see anything wrong with picking up some of the specifics of a language while using a framework.

What do you term as python fundamentals
How's about the Python tutorial?

I would suggest MDN Django tutorial. In this tutorial you will develop a simple local library app and deploy it on heroku. You will get a good idea on how to develop a web app and deploy it on a cloud platform.

Related

Is there a python equivalent to Laravel 4?

Laravel 4 enables me to develop both small scale and enterprise scale app's easily and efficiently, and its modular concepts allow me to extend it core, build custom reusable packages, and easily follow TDD practices.
I have been diving into the wonderful world of python (v3) and wondered what the equivalent web framework would be in the python community? A framework that follows some of the same core concepts built into Laravel 4 such as MVC design pattern, easy testing, modular design, packages etc.
Yes. Pyramid is what you are looking for. It's written from the ground up to be based in common Python libraries and components, and you can swap out pieces for other pieces as you wish. Python as a language is geared for TDD, and Pyramid takes advantage of that. You can push your own libraries, if they are abstract enough, out to PyPi for yourself, if you wish, but you can of course just keep them within your own projects too.
There are other Python frameworks, but if you're looking for modular and extensible, without a whole lot of framework interference in your working style preference, Pyramid is the way to go.
P.S. this question is better suited for programmers.stackexchange.com.
Python also has a web framework called Masonite which is a lot like Laravel. Heavily inspired by Laravel and a lot of Laravel developers can pick it up really easily.
Also has an ORM called Masonite ORM which is heavily inspired by eloquent
You can look at the framework I'm currently building, namely glim. There exists inspiration from play framework & laravel in it. You can get more information from the docs page.
It also has an extension system where developers can integrate to it.
You can look at the extensions I have built;

Give me some awesome Web2py Tip & Tricks which makes you more productive

I have been working with web2py following its official web2py book and got to learn too many things. But a book never teaches a productive workflow. I would like to know what workflow you people use to increase you productivity and understanding of the framework as a whole.
Ex:
I often use Web2py interactive shell to play with database objects and understand how they work.
I use Komodo Edit for development and Google App Engine for hosting.
To better understand web2py have a look at the files in gluon/ - for example tools.py is fairly straightforward.

Which opensource web framework should a C# ASP.NET Guy Learn?

I am a web developer working mainly with C# on ASP.NET (Webforms and MVC)..
I have worked previously with PHP and Other Frameworks and languages of the sort..
I am currently looking and focusing all my development on 2 platforms..
One Proprietary and Industry Class Framework (ASP.NET MVC)
and
One Opensource and Free Framework (Insert framework of choice here)
I have no experience with python or ruby but would like to learn one and use either django or rails..
While i understand both are very different from ASP.NET please advise me which one would be the smoothest transition.. (or the one most worth the migration pain is better!)
Thanks
Daniel
I've been learning rails and loving it. The pain point with it is the documentation - version 3 of rails has just come out, and not all of the documentation you will come across will be up to date. However, you can pretty easily get by.
That said, I'm loving it. Ruby is a very elegant language. You can get a feel for rails by reading through this guide:
http://guides.rubyonrails.org/getting_started.html
I did ASP, then PHP, now ASP .NET for the last 5 years, dabbled with Python now I'm doing some RoR. Don't learn something 'similar' just to get outside of the MSFT stack. Check out Ruby on Rails, it's a different mindset, and you will learn a new way of thinking about a lot of things that will make your ASP .Net code better.
For me Python / Django felt much better and easier. Less magical, but Ruby on Rails is pretty amazing and has a lot going for it.
I would suggest you check out www.tekpub.com where Rob Conrey a MSFT .Net guy does a ton of tutorials including video tutorials on RoR 3.
With open source frameworks, I would choose between RoR and Django. Just stay away from anything PHP-based.
First, I would say learn the base language first, to an extent, and go with the framework built on the language you prefer. For example, I do django because I learned python, not ruby. I tried ruby when I was hired for a rails project (for frontend work, but nevermind), and it just felt too... "fluffy" for my taste.
Second, there's the issue of documentation. Django's docs are always up-to-date (keeping them so is part of the django development process) on 99% of topics you would want to look up, and are fairly easy to follow once you get the basics. The other 1% of things you would want to look up are generally completely undocumented, derivable from the source or else not possible (often possible with a third-party app, though, which are easily found). I can't speak too much for rails, but I was able to find little usable documentation in my short foray into it; perhaps I'm just too used to Django's docs.
Finally there's the development environment -- you're likely to have multiple projects on one machine, possibly with conflicting dependencies. With django/python, you get virtualenv and pip as part of the python dev process (or at least you should). These tools work very well for setting up secluded environments for separate projects. Ruby doesn't have any standardized tools for this purpose, but there is a gem called sandbox that worked well enough toward this purpose when I used it; IMO though, it seems as if it has to fight against ruby's natural behavior to get the concept to work. It looks like it hasn't seen active development in a couple years, unfortunately.
Other factors to consider include mass of third-party apps for a framework and size and attitude of the community behind a framework. In the end, though, I guess it comes down to your comfort level among the languages you know and personal preference.
And I will freely admit that I'm rooting for django.
I am a .NET guy and also worked on PHP for a couple of months. At present I am learning Ruby and after completing basics, I am going to move on Rails.
I would suggest you to go with Ruby and than Rails. Career-wise also, Ruby guys are in demand these days, at least in my country.
For a .Net developer try to start with www.pradosoft.com/ prado framework,
it's PHP framework which looks exactly like ASP.NET ..
try it

Using python to develop web application

I have been doing some work in python, but that was all for stand alone applications. I'm curious to know whether any offshoot of python supports web development?
Would some one also suggest a good tutorial or a website from where I can pick up some of the basics of web development using python?
Now that everyone has said Django, I can add my two cents: I would argue that you might learn more by looking at the different components first, before using Django. For web development with Python, you often want 3 components:
Something that takes care
of the HTTP stuff (e.g.
CherryPy)
A templating language
to create your web pages.
Mako
is very pythonic and works with Cherrpy.
If you get your data from a
database, an ORM comes in handy.
SQLAlchemy
would be an example.
All the links above have good tutorials. For many real-world use-cases, Django will be a better solution than such a stack as it seamlessly integrates this functionality (and more). And if you need a CMS, Django is your best bet short of Zope. Nevertheless, to get a good grasp of what's going on, a stack of loosely coupled programs might be better. Django hides a lot of the details.
Edited 3 years later: Don't use mod_python, use mod_wsgi. Flask and Werkzeug are good frameworks too. Needing to know what's going on is useful, but it isn't a requirement. That would be stupid.
Don't lookup Django until you have a good grasp of what Django is doing on your behalf. for you. Write some basic apps using mod_python and it's request object. I just started learning Python for web-development using mod_python and it has been great.
mod_python also uses a dispatcher in site-packages/mod_python/publisher.py. Have a ganders through this to see how requests can be handled in a simple-ish way.
You may need to add a bit of config to your Apache config file to get mod_python up and running but the mod_python site explains it well.
<Directory /path/to/python/files>
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
</Directory>
And you are away!
use (as a stupidly basic example):
def foo(req):
req.write("Hello World")
in /path/to/python/files/bar.py assuming /path/to is your site root.
And then you can do
http://www.mysite.com/python/files/bar/foo
to see "Hello World". Also, something that tripped me up is the dispatcher uses a lame method to work out the content-type, so to force HTML use:
req.content_type = 'text/html'
Good Luck
After you have a good idea of how Python interacts with mod_python and Apache, then use a framework that does all the boring stuff for you. Up to you though, just my recommendation
If you really don't want to delve into the frameworks - and you should, I heartily recommend Django or Pylons - there's still need to go down the road of CGI. This is a totally out-of-date technology, not to mention slow and inefficient.
There is a standard way of building Python web applications, and it's called WSGI. If you want to roll your own web app from scratch, this is absolutely the way to go.
That said, if you're just starting out, really you should go with one of the frameworks.
Python Wiki: Web Frameworks for Python
If you decide to use Django, the official tutorial is an excellent place to start. The Django Book is also free.
There are a couple of choices for web development. From my experience, your choice will again be dependent on your application. I used django and web.py in production and I am about to deploy an app based on pylons.
Django hides a lot of choices (comes with its ORM and templating). The documentation is extensive and well-written. There are many reusable app available for django, but you will likely to invest a little time in integrating them seamlessly. One thing mentioned on djangocon 08 was the fact, that there is cool stuff in django, which can't be easily
accessed in non-django projects.
web.py impressed me by its raw simplicity. Before I knew it, I wrote a small app (78 lines quasi-wiki) in it.
pylons feels like in the middle of both. I can use sqlalchemy and jinja, all in all a pleasant experience for the start.
Lookup Django.
Python can be used for web development, but there isn't a special language extension or anything in the language that will handle all the HTML generation or that works like PHP.
It's pretty much run through some sort of interpreter on a web server (CGI, mod_python, etc.).
I would recommend looking into Python Web Application Frameworks or how to write Python CGI scripts.
There are quite a few web frameworks for python out there, but the only one I've used is Django, and I really like it.
If you've got a few hours, do the tutorial, I promise you, you'll enjoy it :)
As others have mentioned, one of the more prominent python "offshoots" as you call them would be Django. It is a rather powerful framework that allows you to quickly and securely build web applications. The first place to look would be their overview which gives some insight as to what Django does as a framework.
Going through their tutorial taught me alot about the prominent Model-View-Controler design pattern and how it may be used in a web-development context. I found it a great way to start writing an application that worked and learn by improving it.

Other than basic python syntax, what other key areas should I learn to get a website live?

Other than basic python syntax, what other key areas should I learn to get a website live?
Is there a web.config in the python world?
Which libraries handle things like authentication? or is that all done manually via session cookies and database tables?
Are there any web specific libraries?
Edit: sorry!
I am well versed in asp.net, I want to branch out and learn Python, hence this question (sorry, terrible start to this question I know).
Basic Python syntax isn't half of what you need to know.
All of the Python built-in data structures.
Object-oriented design.
What python module and packages are.
The Python libraries -- almost everything you could ever want has already been written.
To name a few things.
If you've done some web development, you probably have some background in HTTP protocol, HTML, .CSS and Javascript and SQL.
You should use a framework to handle the endless collection of mundane details, like authentication. Look at Django.
Answer replaced to correspond with the updated question.
If you're already familiar with ASP.NET, the easiest way to jump into creating a website with Python is probably to look into one of the major web frameworks. Django is very popular, working through the installation guide and the tutorial will probably get you rolling pretty well.
Really though, I'd personally suggest at least learning the language itself to a basic competency level before trying to dive right into using it inside a web framework. I think you'll be trying to force yourself to learn too much at once. In terms of just learning Python, the free book Dive Into Python is always spoken of highly.
Oh, golly.
Look, this is gonna be real hard to answer because, read as you wrote it, you're missing a lot of steps. Like, you need a web server, a design, some HTML, and so on.
Are you building from the ground up? Asking about Python makes me suspect you may be using something like Zope.
Don't forget to give IronPython a try - your .NET experience can help making sense of newly learned Python idioms.
IronPython is an implementation of the Python programming language running under .NET and Silverlight. It supports an interactive console with fully dynamic compilation. It's well integrated with the rest of the .NET Framework and makes all .NET libraries easily available to Python programmers, while maintaining compatibility with the Python language.
Of course the builtins. And become familiar with the standard library (until you start to remember what's in it, I'd suggest looking through it any time you're about to implement something... It might be there already!)
You'll want some kind of framework, I'd recommend Django or TurboGears
But you also need to learn the pythonic-way. For this, open up a Python interpreter and type:
import this

Categories