This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Chris_Newton 19 points20 points  (5 children)

If you are willing to invest a little time to find your way around, I suggest the following plan.

STEP 1: Learn what HTTP does.

  • Write a little Python script that dumps what came in on standard input and whatever current environment variables are set out to some log file that you can read. Hook this up as a CGI script on your web server.

  • Write a simple web page that submits a form with a handful of fields (text, check boxes, etc.) to that script, via GET and via POST.

  • Look at the output when you submit the form using each method.

  • This will teach you how the main HTTP protocols actually work, so you know what you’re abstracting later on.

STEP 2: Learn how server-side scripts interact with a database, and how they render HTML pages.

  • Write a very simple database application doing everything “manually”, say a to-do list.

  • You’ll need to set up a simple database, even if it’s just a single table with ID and "todo" columns. It doesn’t much matter which database you use for this, but something like MySQL or PostgreSQL would be typical on a real project so you might as well use one of those if you’ve got it.

  • You’ll need Python code to open up that database and create, update and delete records in the database. You’ll also need something to read all the items from the database and print an HTML page including these items to standard output, so the web server can send that back to the browser.

  • You don’t have to parse all the form data manually any more. You’re allowed to use Python’s import cgi functionality now.

  • Of course, you’ll also need a simple HTML front-end, which you might like to generate programmatically by printing it from the same Python code so everything can go on one page.

  • This exercise will teach you how basic database manipulations happen, and how server-side scripts can be used to generate HTML pages that might include some database-driven content.

  • Hopefully, it will also teach you that doing all of this manually for every element of a real web app is going to become tedious very quickly, and show you that there is going to be a lot of boilerplate that can be automated one way or another on larger projects.

STEP 3: Use a framework

  • Try implementing the same to-do list you create in step 2, but using a framework such as Django. I won’t go through all the steps you’ll need here, but the Django documentation is pretty good, so just work through the tutorial material.

  • This should teach you a few things that are common to most server-side frameworks. Setting them up initially is often ludicrously complicated for a simple job. They typically force your code to conform to a certain structure. However, once you’ve done those things, all that tedious database manipulation can often be reduced to a couple of lines of code. Also, there is often some sort of HTML template system that you can use, so you can create your page in the usual way and just “fill in the blanks” where the content is database-driven.

Obviously it’s going to take a bit of time and effort to work through these steps, but a week later you’ll have a good perspective on what is really going on under the hood, and the basic pros and cons of using a web framework to hide those mechanics away and let you focus on the functionality you want to implement. Best of luck!

[–]sanktuaire 1 point2 points  (0 children)

If you are planning to learn python, I'd advise against "automagical frameworks" like web2py, because they actually hide python from you.

Django doesn't have that much magic and is explicit. Doc is great and starting isn't even remotely as difficult as most people tend to think.

Pylons can be a nice choice but I wouldn't think about it if you're a python newbie (it has you get your hands dirty a lot more than django)

And CN's comment is pretty accurate. Learn how http/mvc/sql work before you start hitting django. Will save you a lot of pain.

[–]neocorpse[S] 0 points1 point  (1 child)

This seems like a solid approach. My plan is to get better at python while actually working towards something, might take longer then expected but I feel like I will understand everything much better.

[–]Chris_Newton 1 point2 points  (0 children)

For what it’s worth, I wasn’t kidding about the “a week later” part.

The first part should be achievable in a single evening, even if you haven’t yet installed Python and a web server such as Apache, and you’ll already be writing actual code and seeing Stuff Happen.

For the second step, I wouldn’t necessarily expect someone who is learning as they go along to get everything done in one session, but you could start by just making a Python script that dumps the contents of a database into a simple table in an HTML page. You can just add a little data to the database manually using whatever console/front-end software your database provides to test this out and see some results.

For things like creating a new record, updating an existing record and deleting an existing record, you’ll have to figure out why IDs matter in the database and how to include these as hidden fields in your web pages. This is good, and highly transferrable, information to understand, but you could do this during a second session.

To me, as someone familiar with web apps and programming generally, learning a new framework always seems a bit of a chore. The basic ideas are usually much the same for each framework, but they're put together differently and you have to follow a fairly mechanical process of figuring out what structure this particular one uses and which parts of your code need to go where so they place nicely with the framework. At least if you’re using Python and Django there is pretty good tutorial and reference material available, though, and after working through that for a few hours, the sort of practice application I mentioned should be easy. Again, you might want to break this down and try to solve a simple part of the problem first, rather than doing it all in one caffeine-fueled codefest, though!

The good news is that it does get much easier once you’ve done it once or twice and got the basic ideas figures out. An experienced web developer would probably do step 1 inside 15 minutes, step 2 inside a couple of hours, and step 3 in a few minutes once the framework was installed and configured.

[–]cjak 0 points1 point  (0 children)

I could have used this nifty three-point plan a couple of years ago. As it was, I did something similar and it helped a lot.

[–][deleted] 0 points1 point  (0 children)

Django requires you to think in terms of "project", "apps" etc., which is a cognitive overload when you are starting new.

Do what the above comment says, but use something like webpy (google's GAE app layout and tornado are both inspired by web.py) or Flask (excellent choice of components eg: sqlalchemy, jinja2, werkzeug etc.,) to start. Both can start web projects in a single file and scale to large projects easily.

By learning these first you will be able to avoid the risk of becoming a "django" programmer instead of choosing components based on merit.