Django Poll App

Firstly What Django is?

Django is a free and open source web application framework, written in Python. A web framework is a set of components that helps you to develop websites faster and easier.

This is a perfect tutorial for getting started. Choose the tutorial as per the version of your django installed. One can go with the latest: https://docs.djangoproject.com/en/1.11/intro/tutorial01/

You can install it using:

sudo apt-get install python-django

I had followed the above link to make my django app. I used django version 1.7 and python 3+

Here I am going to discuss about some of my struggles in doing this work:

This app is basically that people can view poll and can vote in that. Admin can add, delete or change polls.

  • The first problem I faced was in below command:
    django-admin.py startproject mysite
    

    This command is for starting a new project. Later on it’s solved by removing .py from above command. As in ubuntu there is django-admin.

  • django-admin is Django’s command-line utility for administrative tasks.
  • In mysite/settings.py, you need to edit as per your database. I had used Mysql so I replaced:

DATABASES = {
    ‘default’: {
        ‘ENGINE’: ‘django.db.backends.sqlite3’,
        ‘NAME’: os.path.join(BASE_DIR, ‘db.sqlite3’),
    }
}

which is of Sqlite with mysql:

DATABASES = {
    ‘default’: {
        ‘ENGINE’: ‘django.db.backends.mysql’,
        ‘NAME’: ‘database name’,
        ‘USER’: ‘root’,
        ‘PASSWORD’: ‘**’,
        ‘HOST’: ‘localhost’,

    }
}

  • I was getting an error when I gave this command:
python manage.py migrate

Error: pymysql not found

Then I installed: sudo apt-get install python-pip

pip install pymysql

  • One more error I was getting that mysql can not be connected to localhost. I had given some random port address in settings.py file after HOST. Then I deleted that line.

Till this point I am done with Django Welcome Page.

Its just a discussion that after that you will see a make migration command. By running makemigrations, you’re telling Django that you’ve made some changes to your models. This reminds me of Commit and push commands of git which finally pushes the changes to the rmeote repository.

Now lets play with API provided by Django,

  • It was silly but I got Indentation Error due to space between >>> and my text.
  • Its good to set different port number if you are working on a server

python manage.py runserver 8100

Basically you are working separately in API, admin and user content.

Part-2 :

111

It’s all about creating an admin page and setting a GUI for managing Question, Choices etc.

11

Part-3

Here comes the section for polls.

1111

 

Advertisements

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