开发者

How to transition from PHP to Python Django?

Here's my background: Decent experience with PHP/MySql. Beginner's experience with OOP

  1. Why I want to learn Python Django? I gave in, based on many searches on SO and reading over some of the answers, Python is a great, clean, and stru开发者_运维问答ctured language to learn. And with the framework Django, it's easier to write codes that are shorter than with PHP

  2. Questions

    1. Can i do everything in Django as in PHP?

    2. Is Django a "big" hit in web development as PHP? I know Python is a great general-purpose language but I'm focused on web development and would like to know how Django ranks in terms of web development.

    3. With PHP, PHP and Mysql are VERY closely related, is there a close relation between Django and Mysql?

    4. In PHP, you can easily switch between HTML, CSS, PHP all in one script. Does Python offer this type of ease between other languages? Or how do I incorporate HTML, CSS, javascript along with Python?


Can i do everything in Django as in PHP?

Always

Is Django a "big" hit in web development as PHP?

Only time will tell.

With PHP, PHP and Mysql are VERY closely related, is there a close relation between Django and Mysql?

Django supports several RDBMS interfaces. MySQL is popular, so is SQLite and Postgres.

In PHP, you can easily switch between HTML, CSS, PHP all in one script.

That doesn't really apply at all to Django.

Or how do I incorporate HTML, CSS, javascript along with Python?

Actually do the Django tutorial. You'll see how the presentation (via HTML created by templates) and the processing (via Python view functions) fit together. It's not like PHP.


  1. Yes.
  2. It's very hard to tell exactly how popular it is.
  3. MySQL is officially supported.
  4. Yes, but probably not in the way you think. Please read this and also follow the tutorial that S.Lott mentions.


  1. No. You can only do a LOT better.
  2. Awesome, popular. Supported by best hosters like Mediatemple.
  3. No. You can just change 'mysql' to 'postgresql' or 'sqlite' in your settings.py.
  4. NO! Python would never give you the right to mix up everything in one file and make the shittest shit in the world. Templates, static server.

Django is a Model-Template-View framework, great for any applications, from small to huge. PHP works fine only with small apps. Yeah, PHP == Personal Home Page, lol.

P.S. Also you can minify your CSS and JS. And compile to one single file (one js, one css). All with django-assets. And yeah, there's a lot more reusable Django apps (for registration, twi/facebook/openid auth, oembed, other stuff). Just search Bitbucket and Github for "django". No need to reinvent a bicycle, like you do with PHP.


In PHP, you can easily switch between HTML, CSS, PHP all in one script. Does Python offer this type of ease between other languages? Or how do I incorporate HTML, CSS, javascript along with Python?

That's one of the reasons why PHP is so easy to learn. And it's also exactly why so many (if not most) PHP projects are such a complete mess. It's what leads to the "spaghetti code" syndrome.

Django is all about complete separation of page design from view logic from URL routing (in fact this is true of most modern MVC or MTV frameworks). So templates are in one place, data structure definitions are in another, and the logic that defines their interaction is in another. It takes a bit of getting used to, but has a huge payoff.

Another thing that takes getting used to for people coming from PHP is that fact that file and foldernames no longer have a direct bearing on the URL. For example in PHP, you might have foldername/filename.php and the URL would be http://example.com/foldername/filename.php. It doesn't work like that in Django. Instead, you define a URL structure in a file (urls.py). In that "map" you define which piece of logic ("view code") will be called when a matching URL is intercepted. Everything is abstracted like that. The result is a much cleaner, more logical site layout and logic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜