Python - Django Creating and Connecting App to the Server

Getting Started

First, we gonna create our website using the Django Framework,. if you haven't done so, you may refer to my tutorial entitled Python Getting Started w/ Django Framework

Creating the App

Go to command prompt and go to the directory folder of your website. In my case, it will be on samplesite. If your server is running, just type Ctrl+c. Type the python that you use like in the getting started tutorial. In my case, I'll type python manage.py startapp sampleapp. This names the app as sampleapp. creatingnewapp This will create new folder in your site directory named sampleapp newfolder

Installing the App

1. Open settings.py located in your site directory. In my case, it will be on samplesite folder. yoursite 2. Install our app by typing the name of the app in INSTALLED_APPS list and save. install

Setting up the URL of our App

1. In your site directory, open urls.py and include our app in the urlpatterns by typing: urls.py 2. In the app folder, open views.py. In my case, it will be on sampleapp folder. This is the thing that our viewers will see. In this tutorial. we're gonna make it simple so we're just gonna type and save this: views.py 3. In the app folder, create urls.py and type then save: urlsapp This will direct to our index located in our views.py.

Running our Server

We now run our server if everything is working. runserver

Test our App

Open you browser then type 127.0.0.1:8000/sampleapp. It should look like this: runapp That ends this tutorial. Happy Coding :)

Add new comment