How to create django app in pythonanywhere

This will be help to create Django first App in pythonanywhere which is very useful for beginners.

create django app

What is mean of app in Django?

It is a web application to use python package that is specifically intended for use in a Django projects.

Process of create Django first app

Here you will learn deploy the Django app with step by step.

I hope you have a already setup Django project if not please click to setup django project

You can see below screen after login pythonanywhere website.

pythonanywhere_home_page

Step : 1

Click on Files Tab

pythonanywhere_file_page

You can see the main directory of pythonanywhere and you can check the list of Django project name.

Step : 2

Here you need to click on project name mysite and it is a directory of project where you can upload the Django project in pythonanywhere.

Also there are two highlighted column first is directory where you can create the multiple Django Apps name and Second is files where you can create the files and write the code.

Step : 3

Now create the Django App directory where you can keep the all Django files.

Here I am creating myapp directory for Django app and you will redirect to new page ,you can see in below screenshot.

pythonanywhere_main_directory

Step : 4

Now you have reached inside of myapp directory. Files and Directory will be empty so now you have to create views.py and urls.py

I am creating both the files views.py and urls.py .

create_first_django_app

Step : 5

Now all the directory and files has been completed and Now need to write the code for showing content in webpage

I will show content name like Welcome to my first Django APP on web page.

Steps of write code in Django Files

  • Click on views.py file and write simple def function for showing content.
  • from django.http import HttpResponse def index(request): return HttpResponse("<br><br><center><h1><b>Welcome to my first Django APP</b></h1></center>")
  • Now back to myapp path and click on urls.py and write the code.
  • from django.conf.urls import url from myapp.views import index urlpatterns = [ url(r'^$',index), ]

  • Now most important thing you have to add one more url in mysite/urls.py
  • How you can add url in mysite/urls.py

    create_views_and_urls

    After the click on mysite directory you will see the multiple files so now you have you click on urls.py and write the one more url.

    from django.contrib import admin from django.conf.urls import url from django.urls import path, include urlpatterns = [ url('admin/', admin.site.urls), url(r'^myapp/',include('myapp.urls')) # add one more url ]

    Now your work has been completed and it's time to reload a web page. click on the Web Tab and click on Reload button for showing data in webpage.

    create_url_in_pyathonanywhere

    Now click on the Domain name for showing you web page and content.

    reload_webapp_in_pythonanywhere

    Hope you like it , please comment if you have any doubt .



    Setup django project in pythonanywhere
    How to upload file in S3 bucket in python
    Free live cricket score API for python

    Post a Comment

    0 Comments