Report of Djangoo
Report of Djangoo
AN INTERNSHIPREPORT
Submitted by
M.MUTHU SUBHA
(953421104030)
Partial fulfilment for
the award of the degree BACHELOR OF
ENGINEERING
In
COMPUTERSCIENCE AND ENGINEERING
VV COLLEGE OF ENGINEERING
TISAYANVILAI-627657
JUNE 19 – JULY 31
VV COLLEGE OF ENGINEERING
TISAYANVILAI- 62765
BONAFIDE CERTIFICATE
1
ABSTRACT
2
TABLE OF CONTENT
01 INTRODUCTION
02 ARCHITECTURE AND
LAYERS OF
DJANGO
03 MODEL LAYER
04 FIELDS
05 VIEW LAYER
06 FORMS
07 TEMPLATE LAYER
08 DEVELOPMENT
PROCESS
09 SIGNALS
10 DEFINING AND
SENDING SIGNALS
11 ADVANTAGES OF
DJANGO
12 APPLICATION OF
DJANGO
13 CONCLUSION
3
1. INTRODUCTION
Django is a Python-based web framework for model-template-view
(MTV) based architectural patterns. It's open-source and is maintained
by the Django Software Foundation.
__init__.py
Settings.py
Urls.py
Wsgi.py
Asgi.py
4
2.
2 ARCHITECTURE
LAYERS OF DJANGO
5
3. MODEL LAYER
EXAMPLE:
fromdjango.dbimport models
classPerson(models.Model):
first_name = models.CharField(max_length=30)
4. FIELDS
The most important part of a model – and the only required part of a
model – is the list of database fields it defines.
Fields are specified by class attributes
6
Field types:
Each field in your model should be an instance of the appropriate Field class.
Django uses the field class types to determine a few things:
• The column type, which tells the database what kind of data to store
(e.g. INTEGER, VARCHAR, TEXT).
• The default HTML widget to use when rendering a form field (e.g.
<input type="text">, <select>).
• The minimal validation requirements, used in Django’s admin and in
automatically-generated forms.
Security
Because a settings file contains sensitive information, such as the
database password, you should make every attempt to limit access to
it. This is especially important in a shared-hosting environment
5. VIEW LAYER
Django has the concept of “views” to encapsulate the logic responsible for
processing a user’s request and for returning the response.
URL dispatcher
A clean, elegant URL scheme is an important detail in a high-quality
Web application. Django lets you design URLs however you want, with
no framework limitations
See Cool URIs don’t change, by World Wide Web creator Tim Berners-
Lee, for excellent arguments on why URLs should be clean and usable
.
7
Overview
This module is pure Python code and is a mapping between URL path
expressions to Python functions (your views).
This mapping can be as short or as long as needed. It can reference
other mappings. And, because it’s pure Python code, it can be
constructed dynamically
Django also provides a way to translate URLs according to the active
language.
6. TEMPLATE LAYER
The template layer provides a designer-friendly syntax for rendering the
information to be presented to the user.
8
It’s a good template library even though it’s fairly opinionated and sports
a few idiosyncrasies.
7. FORMS
Django provides a rich framework to facilitate the creation of forms and the
manipulation of form data.
HTML forms
select options, manipulate objects or controls, and so on, and then send
that information back to the server.
Some of these form interface elements - text input or checkboxes - are
fairly simple and are built into HTML itself.
Forms in Django
We’ve described HTML forms briefly, but an HTML <form> is just one
part of the machinery required.
In the context of a Web application, ‘form’ might refer to that HTML
<form>, or to the Django Form that produces it,
or to the structured data returned when it is submitted, or to the end-to-
end working collection of these parts.
9
Rendering a form in a template involves nearly the same work as
rendering any other kind of object, but there are some key differences.
In the case of a model instance that contained no data, it would rarely if
ever be useful to do anything with it in a template.
o On the other hand, it makes perfect sense to render an unpopulated
form - that’s what we do when we want the user to populate it.
So when we handle a model instance in a view, we typically retrieve it
from the database. When we’re dealing with a form we typically
instantiate it in the view.
When we instantiate a form, we can opt to leave it empty or pre-populate
it, for example with:
• data from a saved model instance (as in the case of admin forms
for editing)
• data that we have collated from other sources
8. DEVELOPMENT PROCESS
Django settings
The basics
10
9. SIGNALS
Django includes a “signal dispatcher” which helps allow decoupled
applications get notified when actions occur elsewhere in the
framework. In a nutshell, signals allow certain senders to notify a set
of receivers that some action has taken place. They’re especially
useful when many pieces of code may be interested in the same events.
Django provides a set of built-in signals that let user code get notified
by Django itself of certain action.
Parameters
Receiver – The callback function which will be connected to this signal.
Sender – Specifies a particular sender to receive signals from.
Weak – Django stores signal handlers as weak references by default.
Thus, if your receiveris a local function, it may be garbage collected. To
prevent this, pass weak=False when youcall the signal’s connect()
method.
Dispatch_uid – A unique identifier for a signal receiver in cases where
duplicate signalsmay be sent.
Defining signals
class Signal(providing_args=list)
All signals are django.dispatch.Signal instances. The providing_argsis a list of
the names of arguments thesignal will provide to listeners. This is purely
documentational, however, as there is nothing that checks that the signalactually
provides these arguments to its listeners.
11
For example:
importdjango.dispatch
pizza_done = django.dispatch.Signal(providing_args=["toppings", "size"])
Sending signals
There are two ways to send signals in Django.
1. Signal.send(sender, **kwargs)
2. Signal.send_robust(sender, **kwargs)
To send a signal, call either Signal.send() (all built-in signals use this) or
Signal.send_robust(). You must provide the sender argument (which is a
class most of the time) and may provide as many other keyword
arguments as you like.
For example, here’s how sending our pizza_done signal might look:
classPizzaStore:
...
pizza_done.send(sender=self.__class__,toppings=toppings, size=size)
Both send() and send_robust() return a list of tuple pairs [(receiver,
response), ... ], representing the list of called receiver functions and their
response values.
send() differs from send_robust() in how exceptions raised by receiver
functions are handled.
send() does not catch any exceptions raised by receivers; it simply allows
errors to propagate. Thus not all receivers may be notified of a signal in
the face of an error.
12
send_robust() catches all errors derived from Python’s Exception class,
and ensures all receivers are notified of the signal. If an error occurs, the
error instance is returned in the tuple pair for the receiver that raised.
The tracebacks are present on the __traceback__ attribute of the errors
returned when calling send_robust().
Disconnecting signals
Signal.disconnect(receiver=None, sender=None,dispatch_uid=None)
To disconnect a receiver from a signal, call Signal.disconnect(). The
arguments are as described in Signal.
connect(). The method returns True if a receiver was disconnected and
False if not.
The receiver argument indicates the registered receiver to disconnect. It
may be None if dispatch_uid is used to identify the receiver.
Messages
The function must return a list of messages. If no problems are found as a
result of the check, the check function must return an empty list.
The warnings and errors raised by the check method must be instances of
CheckMessage. An instance of CheckMessage encapsulates a single
reportable error or warning. It also provides context and hints applicable
to the message, and a unique identifier that is used for filtering purposes.
The concept is very similar to messages from the message framework or
the logging framework. Messages are tagged with a level indicating the
severity of the message.
There are also shortcuts to make creating messages with common levels
easier. When using these classes you can omit the level argument because
it is implied by the class name.
• Debug
• Info
13
11. ADVANTAGES OF DJANGO
14
13. CONCLUSION
Django, a popular & high level python web framework, is Flat out amazing.
Below are few of the reasons.
Disqus, Facebook, Instagram, Pinterest, NASA, The Washington Post and other
top companies use Python with Django. For web developers, this means that
mastering Python and its popular advanced frameworks like Django should
ensure you’re able to find work or even build your own product or service as a
startup.
Python is an ideal option for bootstrappers and startups because of its quick
deployment and—as mentioned earlier—lesser amount of required code next to
Java, C, and PHP among others.
15
16