Django

Django: A Beginners Guide to Learn Part-1

We’re going to begin with the requirements how Django works. What do we need to set up by Django application.

Django: A Beginners Guide to Learn Part-1

Basic requirement before using Django

The first thing in those requirements is going to be Python.

You can follow- Python Programming: Introduction to Coding Language

Now I don’t recommend learning Django without having some previous Python experience and should have Python installed.

But if you don’t that’s OK.

Head over to Python.org or just search Python in your browser.

And if you scroll down to see a download section.

Now throughout the blog I’ll be using Python 3.5.

If you have a later version 3.6, 3.7 as long as it’s a version of Python 3 you should be fine.

If using Python 2.7 you’re going to run into a few problems as we go along through the blog.

So go ahead and select Python 3.5.

And if you scroll down you’ll notice the download section.

Go ahead and download whichever version of or whichever type of download need a Windows Mac whatever.

Now the second thing we’re going to require is a little bit more complicated.

And that’s known as an IDE.

But to make our lives a lot more easier while playing around with Django and writing Django apps we can install something called PyCharm to go ahead and search.

And the first thing that should be PyCharmed by jet brains.

You guys should have no problem whatsoever installing term.

Go ahead and click on download to me down in the community edition because the professional costs us some money.

Download and your download should start.

Once you’re done with pycharm or once you’ve done downloading Pycharm head over.

Creating a new project for Django

All right now we have Pycharm install the next thing is to create our app directory.

Go ahead and open a pycharm.

It should be somewhere maybe in your doc and your apps.

Double click on it and you should see a window.

Now go ahead and select Create a new project.

Your location can be anything.

I’m going to make my documents Django projects and then I’m going to call mine “first project”.

OK.

You can call yours whatever you want.

Just make sure you know where you have saved it and go.

And then for Interpreter make sure it’s the latest version of Python or whatever version of Python you’re using.

Make sure you select 3.5 or higher.

Click create and fantastic.

We now have our Django project right in front of us.

Tips on pycharm interface

Now a few tips of advice just getting to know how this whole pycharm interface works.

On the left hand side we have our directories.

Basically any files and folders that we might require are right in the middle over here that’s where we see all the code to display any file you have to double click on the file alright and then on the bottom you have the python console which is very I guess key and then you have the terminal what you’re going to use right now to go ahead and open up the terminal.

Go ahead and type the following command pip3 install virtual ENV.

OK so I get the same requirement already satisfied but for you virtual ENV should have downloaded.

Now what is virtual in the virtual ENV is a virtual environment.

And basically all it does is instead of having to install Django multiple times for multiple apps on her machine we can do it in a virtual environment so that it doesn’t take up any space on a machine.

Pretty strict pretty straightforward.

So as not we use Pip 3 and not Pip.

The reason being if you have any version of Python supposed 2.7 2.6 like I do people get confused where to install virtual ENV you’re going to get some problems.

So make sure you pip3 installed virtual EMV.

Now we have Pip3 through your virtual ENV install.

Creating virtual environment for Django

The next step is to actually create a virtual environment.

We’re going to do that by saying virtualenv – p Python3env. Hit enter.

And we should see done.

Fantastic.

So now what’s happened is we’ve created a virtual environment called ENV inside of our directory.

If we Double Click in a directory we now see the ENV folder.

Also note one more thing.

We use Python 3 in our Python for the same reason we use Pip3 just to make sure that you typing in the correct command.

Now the last thing we have to do with our virtual environment is activate it.

Go ahead and say Source env/bin/activate.

Hit enter.

And now we see env be in brackets before the terminal which means that it’s been activated.

So now that we have a virtual environment activated we need to help pycharm that hey pycharm.

I want you to install everything and anything inside of our virtual environment.

And not inside or not inside of a machine.

So go ahead and pycharm like preferences on the windows to be quite similar.

And then you want to go to version control but your project first project and select project interpretor once you’re in the project interpreter.

Make sure you change it to your new virtual environment which is going to be something along the lines of /env/bin/python.

Go ahead and select that apply and OK.

Also the last thing we have to do for setting up our directory is going to be installing Django.

Now that Pycharm knows that we’re using Python 3.5.

We can just say pick install Django everything should work properly.

Let’s go let’s take a look and successfully install Django.1.9.

Now if you have a more recent version of Django that’s absolutely fine.

Everything should still work.

Conclusion

We now have created our directory.

We set up a virtual environment and we install Django.

Happy reading!