Learning Django
Today I starting learning the web development framework called Django. This is something I wanted to learn for a long time after dipping my toes with flask a while back. I've heard good things about Django as many people have made their websites using this framework. Big companies like Instagram used Django to help them set up their website and still use Django and python to this day. One of the benefits I heard about Django is that Django is full of more features making it the go-to package if you want to make a web project that can be used for bigger amounts of traffic and making the web project more fleshed out. Flask is known for being a lightweight library. And mainly used for small projects. I've mainly used the flask to make a minimal web interface when I was doing my machine learning projects.
To start learning Django I decided to watch the tutorial series by Corey Schafer which is a youtuber I think I recommended in a previous article. As he is a very great teacher as he can explain hard concepts simply. His youtube channel has a good back for lots of python related topics and general programming topics. I had the set up as follows: having the youtube page on the left side of the computer by turning the browser window to half size. The window on my right was the text editor atom. And I have the command prompt (anaconda) normal size and unanchored.
The first step to Django was to install the library itself. First, I simply made a new conda environment for web development do if I want to install any other library relating to web development (Like flask) I have will dedicated environment to it. Making a new conda environment does not take to long. Simply use this command: conda create --name [insert name environment here] then the command prompt will ask you to proceed by showing this: proceed ([y]/n)? and you simply enter the letter y to make the environment. If you want to know more about conda environments check this link: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands
After the environment is set up you simply use the pip command to install the library. Using this command should install the library via pip. pip install Django. To verify the install worked to use this python -m django --version. This should return the version of Django.
Now to start you need Django to auto-generate some code of you. Make sure your command prompt is in the directory where you want to write your code. Then run this command: django-admin startproject [insert name here] this generate the code that the site will use. The folder crate should look like something like this
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
Now to see if the website is correctly generated you need to run this command: python manage.py runserver. Your command prompt should print you something like this:
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
January 11, 2019 - 15:50:53
Django version 2.1, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
This is a lightweight web server used for development and debugging the website you made. When you open the IP address in your browser you should get a Congratulations on the web page should the loading of the web page was successful. From here you can start to customise your website.
I will write more about this project in the next post.