Author: saqibkhan
-
Cookies Handling
Sometimes you might want to store some data on a per-site-visitor basis as per the requirements of your web application. Always keep in mind, that cookies are saved on the client side and depending on your client browser security level, setting cookies can at times work and at times might not. To illustrate cookies handling…
-
Apache Setup
So far, in our examples, we have used the Django dev web server. But this server is just for testing and is not fit for production environment. Once in production, you need a real server like Apache, Nginx, etc. Let’s discuss Apache in this chapter. Serving Django applications via Apache is done by using mod_wsgi.…
-
File Uploading
It is generally useful for a web app to be able to upload files (profile picture, songs, pdf, words…..). Let’s discuss how to upload files in this chapter. Uploading an Image Before starting to play with an image, make sure you have the Python Image Library (PIL) installed. Now to illustrate uploading an image, let’s…
-
Form Processing
Creating forms in Django, is really similar to creating a model. Here again, we just need to inherit from Django class and the class attributes will be the form fields. Let’s add a forms.py file in myapp folder to contain our app forms. We will create a login form. myapp/forms.py As seen above, the field type can…
-
Generic Views
In some cases, writing views, as we have seen earlier is really heavy. Imagine you need a static page or a listing page. Django offers an easy way to set those simple views that is called generic views. Unlike classic views, generic views are classes not functions. Django offers a set of classes for generic…
-
Sending E-mails
Django comes with a ready and easy-to-use light engine to send e-mail. Similar to Python you just need an import of smtplib. In Django you just need to import django.core.mail. To start sending e-mail, edit your project settings.py file and set the following options − Sending a Simple E-mail Let’s create a “sendSimpleEmail” view to…
-
Page Redirection
Page redirection is needed for many reasons in web application. You might want to redirect a user to another page when a specific action occurs, or basically in case of error. For example, when a user logs in to your website, he is often redirected either to the main home page or to his personal…
-
Page Not Found (404)
What is 404 Page Not Found Error? The HTTP protocol defines various status codes to indicate different types of HTTP responses. “404” is the HTTP status code that corresponds to the situation when the server cannot find the requested webpage. It is called as “404 error”, also known as the “404 Not Found error” or…
-
Add CSS Files
CSS (Cascading Style Sheets) is an important component of the World Wide Web alongside HTML and JavaScript. It is a style sheet language used for specifying the presentation and styling of a document written in HTML. CSS Files are Static Assets In Django, CSS files are termed as static assets. They are placed in the static…
-
Add Static Files
What are Static Files in Django? The django template language allows data to be inserted in a web page dynamically. However, a web application also needs certain resources such as images, JavaScript code and style sheets to render the complete web page. These types of files are called static files. In a Django application, these files…