Create A Django Application
First of all activate virtual environment. Then create a new App.
python manage.py startapp mynewapp
Type ‘ls’ for look directory. You can see the mynewapp folder is there. Go inside the mynewapp folder there is:
__init__.py: Thread our shop as a module (Empty file)
admin.py: In this files we can put the necessary configuration for admin backend.
apps.py: Any application configuration goes this file.
models.py: Database and table models.
tests.py: Run tests, for sure application work fine.
views.py: Frontend side of the site.
Register The New Application
Go to myapp\settings.py (Attention: it is not mynewapp directory please up one folder) . Add your new app there inside INSTALLED_APPS array
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'mynewapp', # Here your new app
]
Create a Example View ( Lets Check Is Your Application Work? )
Open mynewapp\views.py and import HttpResponse
from django.http import HttpResponse
Then create method for handle requests
def index(request):
text_var = 'This is my newapp page'
return HttpResponse(text_var);
Go to myapp\urls.py (Attention: it is not mynewapp directory please up one folder) . Import mynewapp views
from mynewapp import views
Add new url pattern after admin url
path('',views.index, name='index'),
And run server. Good Luck.