Browse Source

Solution of 04

Praktikum_04_Lsg
Sally Zeitler 5 years ago
parent
commit
1d65d9c9a3
6 changed files with 66 additions and 6 deletions
  1. 2
    1
      MEIM_Lsg/urls.py
  2. 5
    0
      MEIM_Lsg/views.py
  3. 1
    1
      posts/urls.py
  4. 7
    4
      posts/views.py
  5. 41
    0
      templates/base.html
  6. 10
    0
      templates/index.html

+ 2
- 1
MEIM_Lsg/urls.py View File

""" """
from django.contrib import admin from django.contrib import admin
from django.urls import include, path from django.urls import include, path
import posts
from . import views


urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', views.index, name='posts'),
path('posts/', include('posts.urls'), name='posts') path('posts/', include('posts.urls'), name='posts')
] ]

+ 5
- 0
MEIM_Lsg/views.py View File

from django.shortcuts import render
# Create your views here.

def index(request):
return render(request, 'index.html')

+ 1
- 1
posts/urls.py View File

urlpatterns = [ urlpatterns = [
# use re_path for regex (.*) - this regex accepts anything - see https://docs.python.org/3/library/re.html for more # use re_path for regex (.*) - this regex accepts anything - see https://docs.python.org/3/library/re.html for more
path('', views.home, name=''), path('', views.home, name=''),
re_path('(?P<value>.*)/$', views.home, name='textwiedergabe')
re_path('(?P<value>.*)/$', views.home, name='textausgabe')
] ]

+ 7
- 4
posts/views.py View File

from django.http import HttpResponse
from django.shortcuts import render
# Create your views here. # Create your views here.


# if no value is given use the default ''
def home(request, value=''):
return HttpResponse(value)
def home(request, value=""):
context = {
"title": "Beboop",
"message": value
}
return render(request, 'index.html', context)

+ 41
- 0
templates/base.html View File

<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<title>{% block title %} {% endblock %}</title>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand">MEIM</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="/posts">Posts</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.th-nuernberg.de/fakultaeten/efi/">Efi</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://www.google.com/">Google</a>
</li>
</ul>
</div>
</nav>
{% block content %} {% endblock %}

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
</body>
</html>

+ 10
- 0
templates/index.html View File

{% extends "base.html" %}

{% block title %} {{ title }} {% endblock title %}

{% block content %}
<div class="jumbotron">
<h1 class="display-6">My first post!</h1>
<p class="lead">{{message}}</p>
</div>
{% endblock content %}

Loading…
Cancel
Save