Django on Fedora 26

Installing Miniconda 3

From the Official Website of Miniconda, download the package and save it in the script miniconda:Then, give it permission of execution and execute the script into /opt/conda

sudo ~/miniconda.sh -b -p /opt/conda

Then, you might delete the script to install and set the owners and permissions:

 

Link the packages conda to set them in the path and call then from terminal:Now create the environment to work with Python 3

 

 

Then, activate the new environment as the command suggested:

 

 

 

Installing Django

Use the command pip install command to install and check the version: 1.11.5

Creating a project

I am going to create the linuxatuni project inside my development file

The explanation of each file created and in general of this post is in the Web

Running the server

Run the server with the script manage.py:

There is a message which says that unapplied migrations have been set and need to be migrate. These files can be verified in the setting file:

 

 

 

 

 

 

 

 

 

Just run the command suggested on the message:Now we are going to be able to run the server:

Let’s check the local server as it is pointed out in the terminal:

Creating a poll

In a different terminal, activate the environment and create the app: startapp

Now we access into the view.py, and the urls.py to write our Hello world:

 

 

 

 

 

 

 

 

 

Please see the local server

 

 

 

Creating models

To create a question and choice as models, let’s write into the models.py:Then add the Polls.app.PollsConfig into the settings file, an activate it with

 

 

 

 

 

You can migrate the elements we have created as the question and choice

The sqlmigrate command takes migration names and returns their SQL:

Finally, run migrate again to create those model tables in your database:

Working with the terminal

Now let’s write some labels to the question created by using the shell:

Let’s add the method __str__ to both objects: Question and Choice:

Now that we have set the datetime, we can work with them using the terminal

There is not other question set and that is why an error message is displayed. Let’s continue with the queries and choices we are going to set:

 

Creating an admin user

We can run the command to create a superuser called admin

Now you can login into the local server as admin

Then, you can see the objects to manage, in this case groups and users:

 

Make the poll app displayed and modifiable as admin

Import the Question model into the admin.py file in polls:

 

 

Now it is shown the Questions object in Polls:

Exploring the web and the model Questions

You can delete the question as selected action and choose the What’s up option

 

 

 

 

 

A confirmation message is going to be displayed too

 

 

 

You can checked that the action was done successfully

Writing more views

Now we can add more views as are defined in detail, results, and vote:

They can be written in the file urls.py as follow:

Add a number inside a poll and the question will have the same number:

 

 

Writing useful views

The output is going to be defined in the index def to publish objects in order

Adding templates

Create a html file that use for to handle the questions inside the templates/polls

Now we use the html file into the index def in the views.py

Update the url file to make it work

Now you can add questions and list them in the local server:

 

 

 

 

Special thanks to Martin Vuelta for being my mentor in the Django adventure 🙂

Advertisements

About Julita Inca

Ingeniero de Sistemas UNAC, Magíster en Ciencias de la Computación PUCP, OPW GNOME 2011, Miembro de la GNOME Foundation desde el 2012, Embajadora Fedora Perú desde el 2012, ganadora del scholarship of the Linux Foundation 2012, experiencia como Admin Linux en GMD y Especialista IT en IBM, con certificaciones RHCE, RHCSA, AIX 6.1, AIX 7 Administrator e ITILv3. Experiencia académica en universidades como PUCP, USIL y UNI. HPC researcher, a simple mortal, like you!
This entry was posted in FEDORA, GNOME, τεχνολογια :: Technology and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s