-
-
Save swkidd/d95e7a98144b834436aebda00551c67f to your computer and use it in GitHub Desktop.
create django app steps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create django app steps | |
# https://docs.djangoproject.com/en/3.0/intro/tutorial01/ | |
django-admin startproject mysite | |
django manage.py startapp appname | |
# create urls.py in app and templates/home.html | |
from django.urls import path | |
from . import views | |
urlpatterns = [ | |
path('', views.HomePageView.as_view(), name='home') | |
] | |
from django.conf import settings | |
from django.views.generic.base import TemplateView | |
from django.shortcuts import render | |
create view for home route | |
class HomePageView(TemplateView): | |
template_name = 'home.html' | |
def get_context_data(self, **kwargs): | |
context = super().get_context_data(**kwargs) | |
context['key'] = context_goes_here | |
return context | |
# add models to admin.py to register in admin panel | |
# | |
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') | |
MEDIA_URL = '/media/' | |
from django.conf.urls.static import static | |
from django.conf import settings | |
urlpatterns = [ | |
path('', include('appname.urls')), | |
path('admin/', admin.site.urls), | |
] | |
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) | |
# add created app to settings | |
INSTALLED_APPS = [ | |
'appname.apps.AppnameConfig', | |
] | |
#start server | |
python3 manage.py runserver 8080 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment