41,99 €
Delivers absolutely everything you will ever need to know to become a master Django programmer
This book assumes you have a basic understanding of the Internet and programming. Experience with Python or Django would be an advantage, but is not necessary. It is ideal for beginner to intermediate programmers looking for a fast, secure, scalable, and maintainable alternative web development platform to those based on PHP, Java, and dotNET.
Mastering Django: Core is a completely revised and updated version of the original Django Book, written by Adrian Holovaty and Jacob Kaplan-Moss - the creators of Django.
The main goal of this book is to make you a Django expert. By reading this book, you'll learn the skills needed to develop powerful websites quickly, with code that is clean and easy to maintain.
This book is also a programmer's manual that provides complete coverage of the current Long Term Support (LTS) version of Django. For developers creating applications for commercial and business critical deployments, Mastering Django: Core provides a complete, up-to-date resource for Django 1.8LTS with a stable code-base, security fixes and support out to 2018.
This comprehensive step-by-step practical guide offers a thorough understanding of all the web development concepts related to Django. In addition to explaining the features of Django, this book provides real-world experience on how these features fit together to build extraordinary apps.
Sie lesen das E-Book in den Legimi-Apps auf:
Seitenzahl: 752
Veröffentlichungsjahr: 2016
Copyright © 2016 Nigel George
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: December 2016
Production reference: 1291116
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78728-114-1
www.packtpub.com
Author
Nigel George
Indexer
Tejal Daruwale Soni
Acquisition Editor
Reshma Raman
Production Coordinator
Aparna Bhagat
Technical Editor
Rashil Shah
Nigel George is a business systems developer who specializes in the application of open source technologies to solve common business problems. He has a broad range of experience in software development—from writing database apps for small business to developing the back end and UI for a distributed sensor network at the University of Newcastle, Australia.
Nigel also has over 15 years experience in technical writing for business. He has written several training manuals and hundreds of technical procedures for corporations and Australian government departments. He has been using Django since version 0.96 and has written applications in C, C#, C++, VB, VBA, HTML, JavaScript, Python and PHP.
He has another book on Django—Beginning Django CMS—published by Apress in December 2015.
Nigel lives in Newcastle, NSW, Australia.
First and foremost, I would like to thank the original authors of the Django Book-Adrian Holovaty and Jacob Kaplan-Moss. They provided such a strong foundation that it has really been a delight writing this new edition.
Equal first in the shout out has to be the Django community. Vibrant and collaborative, the Django community is what really stood out to this cynical old businessman many years ago when I first discovered the “new kid on the webframework block”. It’s your support that makes Django so great. Thank you.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www.packtpub.com/mapt
Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.
Required programming knowledge
Readers of this book should understand the basics of procedural and object-oriented programming: control structures (such as if, while, or for), data structures (lists, hashes/dictionaries), variables, classes, and objects. Experience in web development is, as you may expect, very helpful, but it is not required to understand this book. Throughout the book, I try to promote best practices in web development for readers who lack this experience.
Required Python knowledge
At its core, Django is simply a collection of libraries written in the Python programming language. To develop a site using Django, you write Python code that uses these libraries. Learning Django, then, is a matter of learning how to program in Python and understanding how the Django libraries work. If you have experience programming in Python, you should have no trouble diving in. By and large, the Django code doesn't perform a lot of magic (that is, programming trickery whose implementation is difficult to explain or understand). For you, learning Django will be a matter of learning Django's conventions and APIs.
If you don't have experience programming in Python, you're in for a treat. It's easy to learn and a joy to use! Although this book doesn't include a full Python tutorial, it highlights Python features and functionality where appropriate, particularly when code doesn't immediately make sense. Still, I recommend you read the official Python tutorial (for more information visit http://docs.python.org/tut/). I also recommend Mark Pilgrim's free book Dive Into Python, available online at http://www.diveintopython.net/ and published in print by Apress.
Required Django version
This book covers Django 1.8 LTS. This is the long term support version of Django, with full support until at least April 2018.
If you have an early version of Django, it is recommended that you upgrade to the latest version of Django 1.8 LTS. At the time of printing (July 2016), the most current production version of Django 1.8 LTS is 1.8.13.
If you have installed a later version of Django, please note that while Django's developers maintain backwards compatibility as much as possible, some backwards incompatible changes do get introduced occasionally. The changes in each release are always covered in the release notes, which you can find at https://docs.djangoproject.com/en/dev/releases/.
For any queries visit: http://masteringdjango.com.
This book assumes you have a basic understanding of the Internet and programming. Experience with Python or Django would be an advantage, but is not necessary. It is ideal for beginner to intermediate programmers looking for a fast, secure, scalable, and maintainable alternative web development platform to those based on PHP, Java, and dotNET.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Type python at a command prompt (or in Applications/Utilities/Terminal, in OS X)."
A block of code is set as follows:
from django.http import HttpResponse def hello(request): return HttpResponse("Hello world")Any command-line input or output is written as follows:
Python 2.7.5 (default, June 27 2015, 13:20:20)[GCC x.x.x] on xxx Type "help", "copyright", "credits" or "license" for more information. >>>New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "You should see the text Hello world-the output of your Django view (Figure 2-1)."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at [email protected] with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.
Great open source software almost always comes about because one or more clever developers had a problem to solve and no viable or cost effective solution available. Django is no exception. Adrian and Jacob have long since retired from the project, but the fundamentals of what drove them to create Django live on. It is this solid base of real-world experience that has made Django as successful as it is. In recognition of their contribution, I think it best we let them introduce Django in their own words (edited and reformatted from the original book).
By Adrian Holovaty and Jacob Kaplan-Moss-December 2009
In the early days, web developers wrote every page by hand. Updating a website meant editing HTML; a redesign involved redoing every single page, one at a time. As websites grew and became more ambitious, it quickly became obvious that that approach was tedious, time-consuming, and ultimately untenable.
A group of enterprising hackers at National Center for Supercomputing Applications (the NCSA where Mosaic, the first graphical web browser, was developed) solved this problem by letting the web server spawn external programs that could dynamically generate HTML. They called this protocol the Common Gateway Interface (CGI), and it changed the web forever. It's hard now to imagine what a revelation CGI must have been: instead of treating HTML pages as simple files on disk, CGI allows you to think of your pages as resources generated dynamically on demand.
The development of CGI ushered in the first generation of dynamic websites. However, CGI has its problems: CGI scripts need to contain a lot of repetitive boilerplate code, they make code reuse difficult, and they can be difficult for first-time developers to write and understand.
PHP fixed many of these problems, and it took the world by storm—it is now the most popular tool used to create dynamic websites, and dozens of similar languages (ASP, JSP, and so on.) followed PHP's design closely. PHP's major innovation is its ease of use: PHP code is simply embedded into plain HTML; the learning curve for someone who already knows HTML is extremely shallow.
But PHP has its own problems; it is very ease of use encourages sloppy, repetitive, ill-conceived code. Worse, PHP does little to protect programmers from security vulnerabilities, and thus many PHP developers found themselves learning about security only once it was too late.
These and similar frustrations led directly to the development of the current crop of third-generation web development frameworks. With this new explosion of web development comes yet another increase in ambition; web developers are expected to do more and more every day.
Django was invented to meet these new ambitions.
Django grew organically from real-world applications written by a web development team in Lawrence, Kansas, USA. It was born in the fall of 2003, when the web programmers at the Lawrence Journal-World newspaper, Adrian Holovaty, and Simon Willison, began using Python to build applications.
The World Online team, responsible for the production and maintenance of several local news sites, thrived in a development environment dictated by journalism deadlines. For the sites—including LJWorld.com, Lawrence.com, and KUsports.com—journalists (and management) demanded that features be added and entire applications be built on an intensely fast schedule, often with only day's or hour's notice. Thus, Simon and Adrian developed a time-saving web development framework out of necessity—it was the only way they could build maintainable applications under the extreme deadlines.
In summer 2005, after having developed this framework to a point where it was efficiently powering most of World Online's sites, the team, which now included Jacob Kaplan-Moss, decided to release the framework as open source software. They released it in July 2005 and named it Django, after the jazz guitarist Django Reinhardt.
This history is relevant because it helps explain two key things. The first is Django's "sweet spot." Because Django was born in a news environment, it offers several features (such as its admin site, covered in Chapter 5, The Django Admin Site) that are particularly well suited for "content" sites such as Amazon, craigslist.org, and washingtonpost.com that offer dynamic and database-driven information.
Don't let that turn you off, though Django is particularly good for developing those sorts of sites, that doesn't preclude it from being an effective tool for building any sort of dynamic website. (There's a difference between being particularly effective at something and being ineffective at other things.)
The second matter to note is how Django's origins have shaped the culture of its open source community. Because Django was extracted from real-world code, rather than being an academic exercise or commercial product, it is acutely focused on solving web development problems that Django's developers themselves have faced—and continue to face. As a result, Django itself is actively improved on an almost daily basis. The framework's maintainers have a vested interest in making sure Django saves developers time, produces applications that are easy to maintain and performs well under load.
Django lets you build deep, dynamic, interesting sites in an extremely short time. Django is designed to let you focus on the fun, interesting parts of your job while easing the pain of the repetitive bits. In doing so, it provides high-level abstractions of common web development patterns, shortcuts for frequent programming tasks, and clear conventions on how to solve problems. At the same time, Django tries to stay out of your way, letting you work outside the scope of the framework as needed.
We wrote this book because we firmly believe that Django makes web development better. It's designed to quickly get you moving on your own Django projects, and then ultimately teach you everything you need to know to successfully design, develop, and deploy a site that you'll be proud of.
Getting Started
There are two very important things you need to do to get started with Django:
The first, installing Django, is really simple and detailed in the first part of this chapter. The second is just as important, especially if you are a new programmer or coming from using a programming language that does not clearly separate the data and logic behind your website from the way it is displayed. Django's philosophy is based on loose coupling, which is the underlying philosophy of MVC. We will be discussing loose coupling and MVC in much more detail as we go along, but if you don't know much about MVC, then you best not skip the second half of this chapter because understanding MVC will make understanding Django so much easier.
Before you can start learning how to use Django, you must first install some software on your computer. Fortunately, this is a simple three step process:
If this does not sound familiar to you don't worry, in this chapter, lets assume that you have never installed software from the command line before and will lead you through it step by step.
I have written this section for those of you running Windows. While there is a strong *nix and OSX user base for Django, most new users are on Windows. If you are using Mac or Linux, there are a large number of resources on the Internet; with the best place to start being Django's own installation instructions. For more information visit https://docs.djangoproject.com/en/1.8/topics/install/.
For Windows users, your computer can be running any recent version of Windows (Vista, 7, 8.1, or 10). This chapter also assumes you're installing Django on a desktop or laptop computer and will be using the development server and SQLite to run all the example code in this book. This is by far the easiest and the best way to setup Django when you are first starting out.
If you do want to go to a more advanced installation of Django, your options are covered in Chapter 13, Deploying Django, Chapter 20, More on Installing Django, and Chapter 21, Advanced Database Management.
If you are using Windows, I recommend that you try out Visual Studio for all your Django development. Microsoft has made a significant investment in providing support for Python and Django programmers. This includes full IntelliSense support for Python/Django and incorporation of all of Django's command line tools into the VS IDE.
Best of all it's entirely free. I know, who would have expected that from M$??, but it's true!
See Appendix G, Developing Django with Visual Studio for a complete installation guide for Visual Studio Community 2015, as well as a few tips on developing Django in Windows.
Django itself is written purely in Python, so the first step in installing the framework is to make sure you have Python installed.
Django version 1.8 LTS works with Python version 2.7, 3.3, 3.4 and 3.5. For each version of Python, only the latest micro release (A.B.C) is supported.
If you are just trialling Django, it doesn't really matter whether you use Python 2 or Python 3. If, however, you are planning on eventually deploying code to a live website, Python 3 should be your first choice. The Python wiki (for more information visit https://wiki.python.org/moin/Python2orPython3, puts the reason behind this very succinctly:
Short version: Python 2.x is legacy, Python 3.x is the present and future of the language
Unless you have a very good reason to use Python 2 (for example, legacy libraries), Python 3 is the way to go.
NOTE: All of the code samples in this book are written in Python 3
If you're on Linux or Mac OS X, you probably have Python already installed. Type python at a command prompt (or in Applications/Utilities/Terminal, in OS X). If you see something like this, then Python is installed:
Python 2.7.5 (default, June 27 2015, 13:20:20)[GCC x.x.x] on xxxType "help", "copyright", "credits" or "license" for more information.You can see that, in the preceding example, Python interactive mode is running Python 2.7. This is a trap for inexperienced users. On Linux and Mac OS X machines, it is common for both Python 2 and Python 3 to be installed. If your system is like this, you need to type python3 in front of all your commands, rather than python to run Django with Python 3.
Assuming Python is not installed on your system, we first need to get the installer. Go to https://www.python.org/downloads/, and click the big yellow button that says Download Python 3.x.x.
At the time of writing, the latest version of Python is 3.5.1, but it may have been updated by the time you read this, so the numbers may be slightly different.
DO NOT download version 2.7.x as this is the old version of Python. All of the code in this book is written in Python 3, so you will get compilation errors if you try to run the code on Python 2.
Once you have downloaded the Python installer, go to your Downloads folder and double-click the file python-3.x.x.msi to run the installer. The installation process is the same as any other Windows program, so if you have installed software before, there should be no problem here, however, the is one extremely important customization you must make.
Do not forget this next step as it will solve most problems that arise from an incorrect mapping of pythonpath (an important variable for Python installations) in Windows.
By default, the Python executable is not added to the Windows PATH statement. For Django to work properly, Python must be listed in the PATH statement. Fortunately, this is easy to rectify:
Figure 1.1: Add Python to PATH (Version 3.4.x).
In Python 3.5.x you make sure Add Python 3.5 to PATH is checked before installing (Figure 1.2).Figure 1.2: Add Python to PATH (Version 3.5.x).
Once Python is installed, you should be able to re-open the command window and type python at the command prompt and get something like this:
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>>While you are at it, there is one more important thing to do. Exit out of Python with CTRL+C. At the command prompt type, the following and hit enter:
python-m pip install-U pipThe output will be something similar to this:
C:\Users\nigel>python -m pip install -U pipCollecting pip Downloading pip-8.1.2-py2.py3-none-any.whl (1.2MB) 100% |################################| 1.2MB 198kB/sInstalling collected packages: pipFound existing installation: pip 7.1.2Uninstalling pip-7.1.2:Successfully uninstalled pip-7.1.2Successfully installed pip-8.1.2You don't need to understand exactly what this command does right now; put briefly pip is the Python package manager. It's used to install Python packages: pip is actually a recursive acronym for Pip Installs Packages. Pip is important for the next stage of our install process, but first, we need to make sure we are running the latest version of pip (8.1.2 at the time of writing), which is exactly what this command does.
If you are going to use Microsoft Visual Studio (VS), you can stop here and jump to Appendix G, Developing Django with Visual Studio. VS only requires that you install Python, everything else VS does for you from inside the Integrated Development Environment (IDE).
All of the software on your computer operates interdependently—each program has other bits of software that it depends on (called dependencies) and settings that it needs to find the files and other software it needs to run (called environment variables).
When you are writing new software programs, it is possible (and common!) to modify dependencies and environment variables that your other software depends on. This can cause numerous problems, so should be avoided.
A Python virtual environment solves this problem by wrapping all the dependencies and environment variables that your new software needs into a file system separate from the rest of the software on your computer.
Some of you who have looked at other tutorials will note that this step is often described as optional. This is not a view I support, nor is it supported by a number of Django's core developers.
The advantages of developing Python applications (of which Django is one) within a virtual environment are manifest and not worth going through here. As a beginner, you just need to take my word for it—running a virtual environment for Django development is not optional.
The virtual environment tool in Python is called virtualenv and we install it from the command line using pip:
pip install virtualenvThe output from your command window should look something like this:
C:\Users\nigel>pip install virtualenv Collecting virtualenv Downloading virtualenv-15.0.2-py2.py3-none-any.whl (1.8MB)100% |################################| 1.8MB 323kB/sInstalling collected packages: virtualenvSuccessfully installed virtualenv-15.0.2Once virtualenv is installed, you need to create a virtual environment for your project by typing:
virtualenv env_mysiteMost examples on the Internet use env as your environment name. This is bad; principally because it's common to have several virtual environments installed to test different configurations, and env is not very descriptive. For example, you may be developing an application that must run on Python 2.7 and Python 3.4. Environments named env_someapp_python27 and env_someapp_python34 are going to be a lot easier to distinguish than if you had named them env and env1.
In this example, I have kept it simple as we will only be using one virtual environment for our project, so I have used env_mysite. The output from your command should look something like this:
C:\Users\nigel>virtualenv env_mysiteUsing base prefix 'c:\\users\\nigel\\appdata\\local\\programs\\python\\python35-32'New python executable in C:\Users\nigel\env_mysite\Scripts\python.exeInstalling setuptools, pip, wheel...done.Once virtualenv has finished setting up your new virtual environment, open Windows Explorer and have a look at what virtualenv created for you. In your home directory, you will now see a folder called \env_mysite (or whatever name you gave the virtual environment). If you open the folder, you will see the following:
\Include \Lib \Scripts \srcvirtualenv has created a complete Python installation for you, separate from your other software, so you can work on your project without affecting any of the other software on your system.
To use this new Python virtual environment, we have to activate it, so let's go back to the command prompt and type the following:
env_mysite\scripts\activateThis will run the activate script inside your virtual environment's \scripts folder. You will notice your command prompt has now changed:
(env_mysite) C:\Users\nigel>The (env_mysite) at the beginning of the command prompt lets you know that you are running in the virtual environment. Our next step is to install Django.
Now that we have Python and are running a virtual environment, installing Django is super easy, just type the command:
pip install django==1.8.13This will instruct pip to install Django into your virtual environment. Your command output should look like this:
(env_mysite) C:\Users\nigel>pip install django==1.8.13 Collecting django==1.8.13 Downloading Django-1.8.13-py2.py3-none-any.whl (6.2MB) 100% |################################| 6.2MB 107kB/s Installing collected packages: django Successfully installed django-1.8.13In this case, we are explicitly telling pip to install Django 1.8.13, which is the latest version of Django 1.8 LTS at the time of writing. If you are installing Django, it's good practice to check the Django Project website for the latest version of Django 1.8 LTS.
In case you were wondering, typing in pip install django will install the latest stable release of Django. If you want information on installing the latest development release of Django, see Chapter 20, More On Installing Django.
For some post-installation positive feedback, take a moment to test whether the installation worked. At your virtual environment command prompt, start the Python interactive interpreter by typing python and hitting enter. If the installation was successful, you should be able to import the module django:
(env_mysite) C:\Users\nigel>python Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import django >>> django.get_version() 1.8.13'This step is not necessary in order to complete any of the examples in this book. Django comes with SQLite installed by default. SQLite requires no configuration on your part. If you would like to work with a large database engines like PostgreSQL, MySQL, or Oracle, see Chapter 21, Advanced Database Management.
Once you've installed Python, Django and (optionally) your database server/library, you can take the first step in developing a Django application by creating a project.
A project is a collection of settings for an instance of Django. If this is your first time using Django, you'll have to take care of some initial setup. Namely, you'll need to auto-generate some code that establishes a Django project: a collection of settings for an instance of Django, including database configuration, Django-specific options, and application-specific settings.
I am assuming at this stage you are still running the virtual environment from the previous installation step. If not, you will have to start it again with:
env_mysite\scripts\activate\From your virtual environment command line, run the following command:
django-admin startproject mysiteThis will create a mysite directory in your current directory (in this case \env_mysite\). If you want to create your project in a directory other than the root, you can create a new directory, change into that directory and run the startproject command from there.
Warning!
You'll need to avoid naming projects after built-in Python or Django components. In particular, this means you should avoid using names such as "django" (which will conflict with Django itself) or "test" (which conflicts with a built-in Python package).
Let's look at what startproject created:
mysite/ manage.py mysite/ __init__.py settings.py urls.py wsgi.pyThese files are:
Now, edit mysite/settings.py. It's a normal Python module with module-level variables representing Django settings. First step while you're editing settings.py, is to set TIME_ZONE to your time zone. Note the INSTALLED_APPS setting at the top of the file. That holds the names of all Django applications that are activated in this Django instance. Apps can be used in multiple projects, and you can package and distribute them for use by others in their projects. By default, INSTALLED_APPS contains the following apps, all of which come with Django:
These applications are included by default as a convenience for the common case. Some of these applications makes use of at least one database table though, so we need to create the tables in the database before we can use them. To do that, run the following command:
python manage.py migrateThe migrate command looks at the INSTALLED_APPS setting and creates any necessary database tables according to the database settings in your settings.py file and the database migrations shipped with the app (we'll cover those later). You'll see a message for each migration it applies.
Let's verify your Django project works. Change into the outer mysite directory, if you haven't already, and run the following commands:
python manage.py runserverYou'll see the following output on the command line:
Performing system checks... 0 errors foundJune 12, 2016-08:48:58Django version 1.8.13, using settings 'mysite.settings'Starting development server at http://127.0.0.1:8000/Quit the server with CTRL-BREAK.You've started the Django development server, a lightweight web server written purely in Python. We've included this with Django so you can develop things rapidly, without having to deal with configuring a production server—such as Apache—until you're ready for production.
Now's a good time to note: don't use this server in anything resembling a production environment. It's intended only for use while developing.
Now that the server's running, visit http://127.0.0.1:8000/ with your web browser. You'll see a "Welcome to Django" page in pleasant, light-blue pastel (Figure 1.3). It worked!
Automatic reloading of runserver
The development server automatically reloads Python code for each request as needed. You don't need to restart the server for code changes to take effect. However, some actions such as adding files don't trigger a restart, so you'll have to restart the server in these cases.
Django's welcome page
MVC has been around as a concept for a long time, but has seen exponential growth since the advent of the Internet because it is the best way to design client-server applications. All of the best web frameworks are built around the MVC concept. At the risk of starting a flame war, I contest that if you are not using MVC to design web apps, you are doing it wrong. As a concept, the MVC design pattern is really simple to understand:
Where it gets difficult is the vastly different interpretations of what actually happens at each layer-different frameworks implement the same functionality in different ways. One framework guru might say a certain function belongs in a view, while another might vehemently defend the need for it to be on the controller.
You, as a budding programmer who Gets Stuff Done, do not have to care about this because, in the end, it doesn't matter. As long as you understand how Django implements the MVC pattern, you are free to move on and get some real work done. Although, watching a flame war in a comment thread can be a highly amusing distraction...
Django follows the MVC pattern closely, however, it does use its own logic in the implementation. Because the C is handled by the framework itself and most of the excitement in Django happens in models, templates and views, Django is often referred to as an MTV framework. In the MTV development pattern:
This is probably the only unfortunate bit of naming in Django, because Django's view is more like the controller in MVC, and MVC's view is actually a Template in Django. It is a little confusing at first, but as a programmer getting a job done, you really won't care for long. It is only a problem for those of us who have to teach it. Oh, and to the flamers of course.
Now that you have everything installed and the development server running, you're ready to move on to Django's views and learning the basics of serving web pages with Django.
