Browse Source

Fix minor errors in code; Add root page

devel
Heimbs 5 years ago
parent
commit
96a0a7a497

+ 2
- 1
news/news/urls.py View File

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


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

+ 15
- 0
news/news/views.py View File

from django.shortcuts import render
from django.http import HttpResponse

logger = None

def init_loger():
global logger
if not logger:
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler)

# Create your views here.
def index(request):
return render(request, 'news/index.html')

+ 24
- 0
news/posts/migrations/0001_initial.py View File

# Generated by Django 2.2.6 on 2019-11-19 12:29

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Notice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('notice_title', models.CharField(max_length=80)),
('notice_text', models.CharField(max_length=400)),
('pub_start', models.DateTimeField()),
('pub_end', models.DateTimeField()),
],
),
]

+ 1
- 1
news/posts/urls.py View File

from . import views from . import views


urlpatterns = [ urlpatterns = [
path('', views.index, name='index')
path('', views.index, name='posts')
] ]

+ 12
- 2
news/posts/views.py View File

from django.http import HttpResponse from django.http import HttpResponse
from .models import Notice from .models import Notice
from django.utils import timezone from django.utils import timezone
import logging

logger = None

def init_loger():
global logger
if logger == None:
logger = logging.getLogger('django.db.backends')
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())


# Create your views here. # Create your views here.
def index(request): def index(request):
init_loger()
notices = Notice.objects.all() notices = Notice.objects.all()
notices = Notice.objects.filter(pub_start__lte=timezone.now())
notices = Notice.objects.filter(pub_end__gte=timezone.now())
notices = Notice.objects.filter(pub_start__lte=timezone.now(), pub_end__gte=timezone.now())
context = { context = {
"notices": notices, "notices": notices,
} }

+ 1
- 1
news/templates/navbar.html View File

<a class="nav-link" href="{% url 'index' %}">Home</a> <a class="nav-link" href="{% url 'index' %}">Home</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{% url 'index' %}">Posts</a>
<a class="nav-link" href="{% url 'posts' %}">Posts</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="https://www.th-nuernberg.de/fakultaeten/efi/">EFI</a> <a class="nav-link" href="https://www.th-nuernberg.de/fakultaeten/efi/">EFI</a>

+ 13
- 0
news/templates/news/index.html View File

{% extends 'base.html' %}

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

{% block content %}
<div class="jumbotron">
<h1 class="display-4">Index of News App</h1>

<p class="lead">Some placeholder Text</p>
</div>
{% endblock %}

Loading…
Cancel
Save