Web programming tutorial [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I'm a programmer with some experience working on various languages and platforms, but I lack any web development experience (apart of some very basic HTML produced by PHP).
I'm looking for a tutorial about the basics of web programming under Linux. I am less interested with apache configuration and server maintenance which I know quite well, but with the actual building of a website using modern techniques. I am familiar with python, but I'll handle any scripting language quite well.
Do you have any recommendations? Can you tell anything about the W3Schhools tutorials?
Bunch of thanks,
Udi

This is a fairly broad question you are asking. You have to be aware that there are a lot of potential answers, the ones already given here being decent ones. And you have to be aware that it is very much a platform decision that you make, whatever tutorial you choose. And that's because web (application) development is a complex thing that can be addressed on various levels (particularly outside the MS world).
I have no close knowledge about the W3Schools you mention, but on first glance it looks they will be teaching you a lot of basic frontend technology: HTML, XHTML, Javascript, CSS and the like. This is not bad and will give you a solid foundation in these things. But web development is usually not done on this level, as it is too tedious and inflexible for larger applications. And you would be missing out on backend/database technology altogether.
Then there are platforms (and I would guess this is the majority) which have a templating approach. You implement page and business logic in a mix of HTML and programming code in some language (Python, Perl, PHP, ...) within an HTML file that is then processed by an engine to generate the final HTML for the user interface and transaction code for the database. Django and TurboGears are the prominent Python representatives of this, Ruby on Rails probably the biggest name currently. But there are a lot others (how about Scala/Lift?), so it's worth taking the time to see which one you like best. They usually do a good job for the database handling. On the UI side you still have page changes.
In that vein there are platforms that try to move away from HTML with embedded code to a pure programmatical approach. You just write code and use specific APIs of the given platform. "Compiling" your project in one way or the other will then generate all the necessary stuff which you have to deploy in a runtime environment. I think Google's GWT and Eclipse RAP are such approaches, and if you think, dream and breath in Java, this is probably for you.
Yet another approach is interesting when page changes in the browser (the most disruptive part of the web experience) is not good enough anymore, when you want desktop-like user interfaces. The way to attack this is to create "fat web clients", with lots of interaction logic built in, usually in Javascript, and have them interact with a server backend only for essential data transfer using Ajax, REST or RPC protocols. Candidates for the client technology are e.g. qooxdoo or Dojo. On the server side you can still use whatever technology you are comfortable with (from RoR to Servlets and beyond). If I had my pick, I would choose qooxdoo for the frontend, and Erlang/CouchDb on the backend.
You have specifically asked about tutorials, and I haven't mentioned a lot. The point I was trying to make was whatever you choose, it is most likely that you will invest quite a bit of time and effort in that technology since they are all quite deep, and will stick with it for some time. During your evaluation you will also check the instructional material for the given platform (don't forget online videos - they're big these days), but this will inevitably be specific. AFAICS, there is no such thing as a "general introduction" to web programming.

With your Python knowledge, you'll might find tutorials like Django useful. It is modern enough to be used in Google App Engine.
Also try the TurboGears tutorial, another Python web framework. This will give you a different angle on (modern) web programming.
Find an introduction and many pointers to other frameworks on Wikipedia.

Ruby on Rails is really interesting for rapid development. It's clean, it's neat, and it lets you focus on the important things like your database and front end.
There are a plethora of RoR tutorials. There are almost two hundred Railscast tutorial videos on loads of subjects. They get pretty in depth too.
There are also plenty of places to look for help on your current app. APIDock is pretty good for finding method uses and how different parts of Rails work. You might also consider going on freenode IRC and getting in the Ruby chatroom: #ruby.
Hope that's helpful!

ok ... the most important thing is to completely abstract your output mechanism (this may even seem trivial to you, but the truth is, too many people disobey that rule and too few tutorials emphasize this point), so that behind a concise API you have some rendering engine (bet it for HTML, XML, JSON or what so ever), most probably using templates ... this is one of the fundamental aspects of request based web applications (this is the actual difference to desktop apps to me) and covered by any better framework ... using MVC architectures is the next step ... there are tons of MVC frameworks for nearly any server language that do A LOT of work for you ... and MVC is perfect for request based apps ... the seperation between business logic and output generation works just about PERFECT ... the key point to a scalable web application is the implementation of your business logic, which in general always involves databases ... this is also a thing you'll have to work with a lot ... creating good HTML templates is a hell of a work, but i'd claim it is relatively easy once you get the hang of it ... no need to come up with super creative solutions and new approaches here ... plus, to me, styling and skinning is replacable ... it is far more difficult to design a good UI that exposes your functionality in the most efficient way, than to implement it, or even make it fancy ...
in your place, i wouldn't delve too much into CSS unless you really want to DESIGN pages (find someone else to do it. maybe even the HTML templates. seriously, you will learn to hate that VERY quickly, especially if you try to get it work in IE7 or lower). rather try to produce rocksolid semantically well structured HTML (good for SEO and accessibility (look at progressive enhancement for that matter)) and learn JavaScript. look at some good frameworks ... jQuery, Ext ... whatever ... don't reinvent the wheel here ...
apart from that, haxe might be of interest for you ... many helpful libraries on
haxelib ...
well, hope that helps ... ;)
greetz
back2dos

There are a few sources to learn HTML, javascript and CSS which is what you were asking for. w3schools is a little company from Norway with not always very good article, but can be used as a quick reference.
I would recommend the following two
WASP InterAct Curriculum
Web Standards Curriculum
There is also HTTP which most people do not really grok. A good way of understanding HTTP is going through REST as an architecture style. Joe Gregorio has created a wonderful series of articles to implement a Web service step by step.
The RESTful Web
Hope it helps.

If you think testing is important, you might be interested in following a TDD (test-driven-development) approach - so, learning how to test Python web apps is as important as learning how to code Python web apps...
I've written a tutorial that starts from zero, aiming to teach Python web development and TDD at the same time. It covers browser-based testing with Selenium as well as unit testing.
http://www.tdd-django-tutorial.com/
comments and suggestions welcomed!

Related

Running a Python Script on a Website (in the background)

Firstly, apologies for the very basic question. I have looked into other answers but they haven't quite answered what I'm after. I'm confident designing a site in HTML/CSS and have very very basic knowledge of Python.
I want to run a very basic Python script on my website. It analyses tweets about a specific topic, and then posts a sentiment analysis score. I want it to run this sentiment analysis every hour and cache the score.
I have a working Python script which does this in Jupyter Notebook. Could you give me an overview of how I would make this script function online and cache the results? I've read into using Python web frameworks, but from my limited understanding, they seem like overkill?
Thank you for your help!
Could you give me an overview of how I would make this script function online
The key thing would be to uncouple the two parts of your system:
Producing the data
Showing it in a website.
So the first thing to do is have your sentiment-analysis script push its value to a database. The database could be something as simple as a csv file, or it could be a key/value store, or something like MySQL or CouchDB (or hundreds of other choices).
Over on the website you have to make a decision between:
Server-side
Client-side
If the former, you could program in Python if that is what you are most familiar with. Whatever language/framework combination you go for, there will an example tutorial of how to read a value from a database and display it: it is just about the most fundamental thing.
If client-side you will usually be programming in JavaScript. Again you need to choose a framework, but again you should easily be able to find a tutorial to follow.
(Unless you have a good reason to prefer server-side, such as familiarity with an existing framework, or security issues with accessing your database, I'd go with a client-side approach.)
I've read into using Python web frameworks... overkill?
Yes and no. You are going to need some kind of database, and some kind of framework. It would be good to understand the basics of web security, too. If the sentiment analysis is your major goal, all that is going to be a distraction, and it might be better to find a friend who already knows web programming to work with. Or just find a tutorial that is very close to what you want to do, and adapt that.
(P.S. I was going to flag your question as "too broad", but you did ask for an overview, so I hope this helps.)

Python and web development | Mako - a lot of questions [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Not coming from an MVC background, but just working with php purely, one of the greatest challenges was to grasp frameworks and the MVC ideology. While I am sure many adhere to MCV as the standard way to push code, I lack finding basic introductions into frameworks, and while they also do seem quite tedious to get started with, my goal is purely to write some Python code into html documents.
At first glance Mako seemed as the solution to the problem, allowing me to write the Python code into html, but at second glance it seemed to require more work than just "that".
What I simply cannot find an answer to anywhere I have looked is the whole aspect of "how-to-start with Mako".
Looking at the Mako site this comes up:
<%inherit file="base.html"/>
<%
rows = [[v for v in range(0,10)] for row in range(0,10)]
%>
<table>
% for row in rows:
${makerow(row)}
% endfor
</table>
<%def name="makerow(row)">
<tr>
% for name in row:
<td>${name}</td>\
% endfor
</tr>
</%def>
Once again I see the entire templating ideology (yuk) coming up, but I just want to write Python code into my html, period. So some questions that I have are:
Once Mako is installed can I start putting Python code into HTML and it will work?
If not, then I assume I need to put the example code from above into a .py file and put base.html in the same directory? Or do I put the .py file somewhere else?
Will this work like CSS in the sense that I inside the html file include a similar fashioned call to the .py file (or .mako file or whatever its called).
Since it sounds framework'ish, will I need to put the html file and the .py/.mako in the same directory or will they also have to be separated?
EDIT: I may as well ask if I can then call my extensions .psp (even though its not mod_python).
I know many would say that this is stupid and that there are better ways of doing it and that I make a big mistake. But clearly there are no noob tutorials explaining this in finer
details, thus leaving to do it the way I see fit, ie. put Python code inside a file and be done with it.
I also looked on this mod_python, but since it seems as an old solution I would actually like to skip that one. However, I hope there is a "new" solution to embed Python into HTML.
PS. I know all the framework evangelists will jump me, but the intention is not debate how to write code. Since no noob/step-by-step tutorial can be found on either Pythons, Djangos
or Makos website and for that matter Pylons, Pyramid etc. it must therefore be assumed that anyone wanting to do this knows their framework implementation methods by heart. But I dont, so I just want to put Python code into HTML and not spend/waste time on learning something that Python already should solve perfectly in the first place.
PPS. By noob, I mean I would love to know the basics such as. Take this code and put into this type of file and put that file there. Then take this file and do that. I just could not find this what so ever anywhere. Its like a public secret.....
First, understand that unlike PHP - which is a custom developed language exclusively for web development, Python is a general purpose programming language. Using Python you can develop Windows apps, Mac apps, server side scripts, mobile applications, servers, network clients - everything and anything that a general programming allows you do to. Just like Java or C#.
Therefore, there are multiple ways to do web development in Python. Thinking "PHP is web development" is wrong, and thinking "Python web development will be like PHP web development", is also wrong.
Finally, keep in mind that since PHP was designed solely for web development, it "hides" a lot of the sundry details that go into writing code that needs to sit behind a web server and process requests and return responses in a strict format.
To do web development in Python, you first and foremost need to learn Python. This is different than PHP. You learn web development as you learn PHP (since that's its prime purpose). Once you learn Python, you can develop all sorts of applications; and many Python developers don't develop for the web.
Since no noob/step-by-step tutorial can be found on either Pythons,
Djangos or Makos website and for that matter Pylons, Pyramid etc. it
must therefore be assumed that anyone wanting to do this knows their
framework implementation methods by heart.
Mako is a template language (like Smarty). It would be pointless to use it "standalone", just like Smarty is useless without PHP behind it.
All web frameworks have beginner's guides. Some are better than others. Django has one of the best documentation of any. Start here. To use any of the frameworks, you would need to know the methods they expose. Just like you need to know the mysql_* methods of PHP to interact with MySQL.
The rest of your questions stem from the fact that Python is not like PHP; and hence what you have come to expect from PHP you didn't find in the Python ecosystem.

What are the mature CMSs and Blogs built on web2py?

In search of technologies for developing web applications and portals, I recently dabbled into Ruby and Python (from a non-sysadmin point of view .. ie, towards web application development) and immediately fell in love with python. I have since wanted to only spend time on python based technology for everything (LOL). I have an immediate need to build a weblog that is also able to function as a corporate website, so I started seeking possible python solutions.
I have researched all the major frameworks and like zope/plone on the enterprise, so I will eventually do a lot in plone. However, I also need an 'instant' sort of framework that I can roll out very rapidly and use to test out some concepts in a weblog.
Given the amount of excellent python projects out there, that ought to be easy right? .. Well, WRONG. That has been real tough, and in the end I could never figure out whether to go with Django or web2py. Each had excellent advantages. In the end, I have decided to spare myself the agony and play with both of them initially .. with a hope to quickly discovering the strengths of each of them that are better suited to different projects.
I am going with:
Django --> Django-cms, other plugins
web2py --> InstantPress ?, KPax?, other
plugins?
My my main beef is that there seems to be very little extra information about the web2py based Kpax and Instant press, beyond being listed under 'free appliances' in web2py website. I have also not seen a well-established alternative to kpax and instantpress.
Question (to those familiar and experienced with web2py): where can I read more about instantpress or kpax beyond watching 3-year old movies of them? Or is the idea that I should just get on with it by installing and playing with them?
Thanks in advance for all suggestions and info ..
Make sure you've got the current version, Instant Press 2.0. Here's a recent video. Unfortunately, I don't think there's much documentation, though I believe Martin (the creator) is working on that. Note, IP 2.0 is based on Powerpack 2.0 (see video).
More basic options are web2py-cms and VCMS. You might also consider making use of plugin_wiki.
Also, a few text editing plugins that may be useful: web2py_ckeditor, elRTE WYSIWYG Widget, and plugin_managed_html
KPAX is fairly old -- probably not the best option at this point.
Also, there was a recent discussion among some folks who are interested in joining forces to build a full-featured CMS, so hopefully this will receive some attention right after the upcoming release of web2py 2.0 (very soon).
UPDATE: There are also a few new efforts under development:
web2cms
Movuca (a social CMS)
nanahoshi-cms
I am developing a Social-CMS, By now I don't have too much working besides the core compoments. But the plan is to release the 'alpha' in one month. (my deadline with a client)
https://github.com/rochacbruno/Movuca
The project is inspired in vikuit.com (but will work outside GAE)
While mine social-CMS is not ready, you can go with InstantPress or PowerPack (best options for web2py by now)
Here is a link to the demo. Movuca Demo Link
I was in a similar dilemma, but at the end decided to use Django & Django-CMS or FeinCMS.
Although web2py community is nice, there is simply not a single actively developed CMS with some significant number of developers, community etc.
Here is my post to web2py mailing list about it:
It might be that it's not difficult to write decent CMS and/or strong blog engine using web2py framework, but I consider there are more important things to do (or write) than writing Yet Another CMS/blog. ;)

what next after 'dive into python'

I've been meaning to learn another language than java. So I started to poke around with python. I've gone over 'dive into python' so I have a decent knowledge about python now.
where do you suggest I go from here? I dont want to go through another advanced book again and would like to use the python knowledge towards building 'something'.
I've heard that python is good for web crawling, however, I did not see that in dive into python. Can the community suggest how to use my pythong knowledge towards web crawlers or spiders?
That really kind of depends on what you enjoy, or would like to build. Since you haven't said, I'll recommend something I enjoyed instead. Programming Collective Intelligence by Toby Segaran is a fun book, and the examples are all in Python. It might be more interesting to you -- if nothing else, it would give your web crawler something to do with the pages it gathers.
Edit: Fusspawn's suggestion of PyGame is very good, if don't want any more books and just want to "dive in" to something.
You can try my Building Skills in OO Design.
http://homepage.mac.com/s_lott/books/oodesign.html
If you like math try learning Python by solving Project Euler problems using python. Each problem is not too much code and it helped me increase my python skills.
I always find making a small game is a nice way to learn a language
PyGame makes it simple and could help learn more about python. I suggest giving it ago if your that way inclined.
To get started with web crawling, consider the Scrapy framework.
http://scrapy.org/
"Scrapy is a high level scraping and web crawling framework for writing spiders to crawl and parse web pages for all kinds of purposes, from information retrieval to monitoring or testing web sites."
It's still edging towards a first release, but is usable and has decent documentation.
For very basic web scraping, check out Mechanize (for basic web "browsing") and BeautifulSoup (for parsing "html soup"):
http://wwwsearch.sourceforge.net/mechanize/
http://www.crummy.com/software/BeautifulSoup/
One fun thing to do would be to combine these interests with some natural language processing projects. The NLTK book recently published by O'Reilly is available online as well:
http://www.nltk.org/book
Lots of fun to be had combining these interests. :-)
If you want to expand beyond web crawling and don't want to start a your own project (or don't know what to do), check out The Python Challenge. It's a game where you have to solve puzzles with a bit of python code. I really enjoyed it.
Is web crawling something you want to do or just something you think you can accomplish? Python is a good tool for web crawling(see here and here), but if you really just want ANY project to work on to get more familiar to the language/APIs I'd suggest you pick a project that you have a general interest in regardless. That way it'll be easier to stick with to fruition as you already have an interest in the project in addition to an interest in the language.
Find an interesting open source project to participate in. You could start looking on pythonsource or sourceforge.
The Tools/webchecker/ directory, which should be in your Python distribution (otherwise you can get it via the link I gave), is a start -- with lots of limitations (no threading except in wsgui.py, no async operation, ...), but removing some of them would be a great learning experience!
A vastly superior spidering system could be built on top of Twisted, e.g. starting with the snippet at the bottom of this mail (which only gets one page, but in the proper asynchronous way!) and adding the other functionality you see exemplified in webchecker (parse and respect robots.txt, get links from pages, etc, etc).
If you wanna "advanced book", I recommend Alex's Python in a Nutshell, Second Edition, learn quite a lot from the book, and Tarek's Expert Python Programming,we all know it's a advanced book for it's title:) .
For read some open source project, recommend SQLAlchemy and Django.
Maybe try to start you own project is the best way.
Others have said it but I'll repeat: work on something you are interested in or it won't be fun.
If you do decide that a crawler would be fun, take a look at google-kongulo, web spider plugin for Google desktop search. The code is quite short and well-written, so this might make a good base for when you decide what you want to crawl.
If you're specifically interested in crawling the Web, check out the three-part talk called "Scrape the Web" given at PyCon 2009. It's part of this RSS feed.
Read Dive Into Python again, it discusses HTML processing and HTTP web services in chapters 8 and 11.

Where is Python used? I read about it a lot on Reddit

I have downloaded the Pyscripter and learning Python. But I have no Idea if it has any job value , especially in India. I am learning Python as a Hobby. But it would be comforting to know if Python programmers are in demand in India.
Everywhere. It's used extensively by google for one.
See list of python software for more info, and also who uses python on the web?
In many large companies it is a primary scripting language.
Google is using it along with Java and C++ and almost nothing else.
Also many web pages are built on top of python and Django.
Another place is game development. Many games have their engines written in C++ but all the logic in Python.
In other words it is one of the most valuable tools.
This might be of interest for you as well:
Is Python good for big software projects (not web based)?
Are there any good reasons why I should not use Python?
What did you use to teach yourself python?
It definitely has job value. For instance Google requires it. Have a look at Google openings in India:
Excellent programming skills in at
least one of the following languages:
C, C++, Java or Python (C++/Python
preferred)
Not sure about India, but you can get a decent overview of available Python jobs on the python.org jobs page here.
Try looking at Mark Pilgrim's excellent book "Dive Into Python" which is available for download under GNU Free Documentation License.
HTH
cheers,
Rob
In 10 years of web development I've had 1 client have me write an email parsing app with it. Not that it doesn't get used, but I've seen Ruby/php/.net way more often in the wild.
Edit:
From the other posts if you plan on working at Google, it sounds like the language to learn - LOL!
It's juste one example but I know it is widely used in large scientific institutions with high tech machinery where non-programmers (typically physicists) need quick prototypes or tools to cover their data collection/processing needs. The easy-to access scripting language aspect clearly plays its role here. So I don't know about building a career out of that only but I'd definitely say that knowing Python is a very valuable asset on your resume, it'll strengthen your "smell of usefulness".
The google app engine lets you use python (or Java). I HIGHLY recommend that you check it out. If you want to have a FREE website with a database (actually a datastore but it works much like a database) using python, THIS IS IT. It scales up too. If you start to get enough traffic you would have to start paying for the usage it requires.
http://code.google.com/appengine/docs/python/overview.html
You could make your own python based site and run some ads. Voila, make some money. Also, I'm sure google could be impressed by some good python because I hear they use it for much of their own sites.

Categories

Resources