GE02 ‐ 3 ‐ Define URI Path and View (Abi Drennan) - wycre/CS3300-Team-2-9 GitHub Wiki

  1. Open django_project urls.py to add a path below the admin path to include the specific urls that will be created in the portfolio_app urls.py. You need to import include:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
#connect path to portfolio_app urls
path('', include('portfolio_app.urls')),
]
  1. Update portfolio_app/views.py by defining the following view for the home page:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):

# Render the HTML template index.html with the data in the context variable.
   return HttpResponse('home page')
  1. Create urls.py file in portfolio_app that contains a path to the defined view:
from django.urls import path
from . import views

urlpatterns = [
#path function defines a url pattern
#'' is empty to represent based path to app
# views.index is the function defined in views.py
# name='index' parameter is to dynamically create url
# example in html <a href="{% url 'index' %}">Home</a>.
path('', views.index, name='index'),
]
  1. Run start server command:
python manage.py runserver
  1. Open http://127.0.0.1:8000/ and you should see home page:
  1. Update portfolio_app/views.py views by defining the following view for the home page:
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def index(request):
# Render index.html
return render( request, 'portfolio_app/index.html')
  1. Open http://127.0.0.1:8000/

    • What do you think is the reason for the issue? In the next part you will fix it.
  2. Version on your Sprint01 branch and update your remote repository:

# add the changes you've made your project files to the staging area
git add .

# commit the changes with a descriptive commit message
git commit -m "Updated views for homepage"

# push the committed change to your remote repository
git push origin Sprint01