ES EN
Thumbnail: django

The Library, application in Django 1.8 | Part I

by , in category Django
4 minute(s) read
Este artículo hace parte de la serie «Django dummies»:
  1. The Library, application in Django 1.8 | Part I
  2. The Library, application in Django 1.8 | Part II
  3. The Library, application in Django 1.8 | Part III
  4. The Library, application in Django 1.8 | Part IV
  5. The Library, application in Django 1.8 | Part V
  6. The Library, application in Django 1.8 | Part VI
  7. The Library, application in Django 1.8 | Part VII

The Beginning.

Today we are going to start an intermediate level application (in my opinion) in Django 1.8, we will use a good handful of concepts, singularities and help that this great web framework offers us, the idea is that at the end of this app, you can continue on your own in creating your own applications or add more functionalities to the one we are going to build.

To follow this series of posts I assume that you already have Python, Django and Virtualenv installed and configured, although the latter is not a primary requirement to follow these posts. We will create a virtual library, where our users will be able to upload books to our platform, they will be able to create a book, edit it or delete it. It should be said that I will use the Windows 7 operating system, if you have not managed to configure Python and Django in this operating system, I recommend reading this entry:

Welcome then to your first application in Django, the web framework for perfectionists.

  1. Start the virtual environment: First things first, we must create our virtual environment, so we go to the place where we want to start our environment: in my case it will be on the desktop, we are going to open our console and in it we put virtualenv virtual-library, we wait for the environment to be built:

creating atmosphere

The next step is to activate the environment we have created. To do this we go to virtual-library/Scripts, where we write activate. We will see that when we press enter, we are given the name of our created environment in parentheses, which means that the environment has been activated.

activating environment

Finally, we must install Django in the environment, we will also need Pillow, a Python library for managing images, since later we will work with images in our app. Having said that, we write in our console pip install Django==1.8, Pillow and wait for them to be installed. It should be added that we must be located in virtual-library

installing

  1. Start the Project: If you don’t have Virtualenv on your machine, no problem, you can start from this step. Open the console, go to the virtual-library folder, (if you don’t have Virtualenv going to the desktop would be a good idea). and place in your console django-admin startproject sitiolectura and press enter.

starting project

This will create the necessary files to start a Django project, within this project we can create the applications we want, let’s look at what this folder looks like:

tree1

Within Sitiolectura, we have a manage.py file, this offers us interactivity with our project; and we have another folder called sitelectura where configuration files, url domains, the __init__.py file are present so that python recognizes that folder as a package, among other important files of our project. Finally, and in order not to make this post longer, we are going to create and register our app.

  1. Create our application: We open the console and at the same level where the manage.py file is, we write python manage.py startapp library, this will create a folder with the fundamental files that we will need as we build our application.

creating app

Ready, we have created our first Django application, the last step we have left to do is register said application in the project, let’s get to it.

  1. Register our application: This is the last step, we must register our application library in our project sitereading, this helps Django to know which application is linked to ‘x’ project. It is a fundamental step. We go to our project folder, that is, sitiolectura/sitiolectura and we open the file settings.py, we go to the INSTALLED_APPS part and we put the following:
	INSTALLED_APPS = (
	    'django.contrib.admin',
	    'django.contrib.auth',
	    'django.contrib.contenttypes',
	    'django.contrib.sessions',
	    'django.contrib.messages',
	    'django.contrib.staticfiles',
	    'library',#With this line we register our app. Don't forget to put the comma at the end.
	)
	

We see that by default, when we build a Django project, it installs several applications, some for managing sessions, messages and authentication. A very useful app is the admin app, which we will see later. Do you want to see the app work for the first time? Open a terminal and go to the same directory where the manage.py file is, then put python manage.py runserver and press enter. Then open your browser and enter the url localhost:8000. Congratulations, your first application with Django is working

working

Well that’s all for now, if you have any questions or if you got stuck on any step, you can let me know below in the comments box.

print("See you soon")

Translated using GPT 5.3 Codex

Siguiente artículo en la serie: The Library, application in Django 1.8 | Part II

application, Django 1.8, Library
comments powered by Disqus