Setting Up Django

None

ZEBEDEE 3 out of 9
Tip

Setting up Django


You’ll need python installed. You can download python here and run the installer.


If you’ve never used Django before, check out the documentation here.


Open VS Code, our code editor, open a folder where you want to store the project and then select Yes, I trust the authors.



Let’s go ahead and create our own virtual environment. Close the welcome screen now and start a new terminal.



Now, go ahead and create a virtual environment. This ensures that all the libraries and packages that you install are only related to this specific app. It’ll also help if you share the code, like I am.


python3 -m venv env



Now let’s go ahead and activate the virtual env.


source ./env/bin/activate


You’ll now see a prefix of (env) in front of your username in the terminal or command prompt.



Let’s install Django, now that we have our virtual environment setup.


python3 -m pip install Django



Awesome! Now we have Django installed. Let’s go ahead and start a project, which is our top-level structure for Django. If you want to follow a verbose guide on Django setup, check out this page.

Run the following command:


django-admin startproject lightning_app




Navigate to the core project directory by entering cd lightning_app into your terminal.



Navigate to the core project directory by entering cd lightning_app into your terminal.



Run the following command to verify your Django installation.

python3 manage.py runserver

And then in your web browser open the link http://127.0.0.1:8000 and you should see the following site.



w00t! We’ve now setup most of Django. Go ahead and close the webserver by heading back to VS Code and pressing CMD (Ctrl) + C. This will stop the webserver.

Let’s now create an app within the Django project . Run the following command.


python manage.py startapp lightning_address_payment



You’ll now see a new folder created for our app. This is where we’ll house most of the code for the Send Payment to Lightning Address 😀.

Now head to the lightning_app/settings.py file and add 'lightning_address_payment' to the INSTALLED_APPS list.

...

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # app added
    'lightning_address_payment'
]

...


Back Next