Posts

Showing posts from August, 2017

Django Processes a Request

Django Processes a Request when we run the Django development server and make requests to Web pages: The command python manage.py runserver imports a file called settings.py from the same directory. This file contains all sorts of optional configuration for this particular Django instance, but one of the most important settings is ROOT_URLCONF. The ROOT_URLCONF setting tells Django which Python module should be used as the URLconf for this Web site. Remember when django-admin.py startproject created the files settings.py and urls.py? Well, the autogenerated settings.py has a ROOT_URLCONF that points to the autogenerated urls.py. Convenient. · When a request comes in—say, a request to the URL /time/—Django loads the URLconf pointed to by the ROOT_URLCONF setting. Then it checks each of the URLpatterns in that URLconf in order, comparing the requested URL with the patterns one at a time, until it finds one that matches. When it finds one that matches, it calls the view function associa...

Python Django 2

Image
Let’s look at what startproject created: mysite/ __init__.py manage.py settings.py urls.py These files are as follows: · __init__.py: A file required for Python treat the directory as a package (i.e., a group of modules) · manage.py: A command-line utility that lets you interact with this Django project in various ways · settings.py: Settings/configuration for this Django project urls.py: The URL declarations for this Django project; a “table of contents” of your Django-powered site A URLconf is like a table of contents for your Django-powered Web site. Basically, it’s a mapping between URL patterns and the view functions that should be called for those URL patterns. It’s how you tell Django, “For this URL, call this code, and for that URL, call that code.” Remember that the view functions need to be on the Python path. urlpatterns = patterns('', (r'^time/$', current_datetime), ) The r in r'^time/$' means that '^time/$ is a ...

Python Django urls:

Django Books: https://djangobook.com/ Installation: http://www.python.org/download/ url patterns: http://www.djangoproject.com/r/python/re-module/.

Histroy of Python Django

Django grew organically from real-world applications written by a Web development team in Lawrence, Kansas. 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 days’ or hours’ notice. Thus, Adrian and Simon 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 Worl...

Python Django 1:

Django: Django is a prominent member of a new generation of Web frameworks. 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. Web application written using the Common Gateway Interface (CGI) standard, a popular way to write Web applications circa 1998. Example code: #!/usr/bin/python import MySQLdb print "Content-Type: text/html" print print "<html><head><title>Books</title></head>" print "<body>" print "<h1>Books</h1>" print "<ul>" connection = MySQLdb.connect(user='me', passwd='letmein', db='my_db') cursor = connection.cursor() cursor.execute("SELECT name FROM books ORDER BY pub_date DESC LIMIT ...

Introduction to python:

introduction vs https://www.youtube.com/watch?v=JNNAOypc6Ek WSGI introduction https://www.fullstackpython.com/wsgi-servers.html mvc https://djangobook.com/the-django-book/ Django ORM (Object relational mappers) models.py contains a description of the database table as a python class. CRUD operations views.py contains the business logic for the page. urls.py specifies which view is called for given url pattern templates/html to render data to user. MVT ( model view template ) MVC ( model view controller ) python interpreter that compiles your application. python environments: which are used by the application app/static: all java script and style sheet app/template html files that are called by views.py forms.py: contains the definitions of the applications forms models.py: classes which define all models of application test.py: contains definition of unit test of application views.py: contains the methods that return all views project_...