신은섭(Shin Eun Seop)

add template

...@@ -38,7 +38,8 @@ INSTALLED_APPS = [ ...@@ -38,7 +38,8 @@ INSTALLED_APPS = [
38 'django.contrib.messages', 38 'django.contrib.messages',
39 'django.contrib.staticfiles', 39 'django.contrib.staticfiles',
40 'rest_framework', 40 'rest_framework',
41 - 'restful.apps.RestfulConfig' 41 + 'restful.apps.RestfulConfig',
42 + 'website'
42 ] 43 ]
43 44
44 MIDDLEWARE = [ 45 MIDDLEWARE = [
......
...@@ -16,7 +16,9 @@ Including another URLconf ...@@ -16,7 +16,9 @@ Including another URLconf
16 from django.contrib import admin 16 from django.contrib import admin
17 from django.conf.urls import url, include 17 from django.conf.urls import url, include
18 18
19 +
19 urlpatterns = [ 20 urlpatterns = [
20 - url('admin/', admin.site.urls), 21 + url(r'^admin/', admin.site.urls),
21 - url(r'^', include('restful.urls')), 22 + url(r'^restapi/', include('restful.urls')),
22 -] 23 + url(r'^', include('website.urls')),
24 +]
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -5,12 +5,13 @@ from django.db import models ...@@ -5,12 +5,13 @@ from django.db import models
5 class File(models.Model): 5 class File(models.Model):
6 created = models.DateTimeField(auto_now_add=True) 6 created = models.DateTimeField(auto_now_add=True)
7 modified = models.DateTimeField(auto_now=True) 7 modified = models.DateTimeField(auto_now=True)
8 - title = models.CharField(max_length=100) 8 + file_name = models.CharField(max_length=100)
9 + # file_name = models.CharField(max_length=100, primary_key=True)
9 object_key = models.CharField(max_length=1025) 10 object_key = models.CharField(max_length=1025)
10 size = models.IntegerField() 11 size = models.IntegerField()
11 # owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE) 12 # owner = models.ForeignKey('auth.User', related_name='snippets', on_delete=models.CASCADE)
12 13
13 class Meta: 14 class Meta:
14 - ordering = ('title',) 15 + ordering = ('file_name',)
15 16
16 17
......
1 +from django.contrib import admin
2 +from website.models import Post
3 +
4 +admin.site.register(Post)
...\ No newline at end of file ...\ No newline at end of file
1 +from django.apps import AppConfig
2 +
3 +
4 +class WebsiteConfig(AppConfig):
5 + name = 'website'
1 +from django.db import models
2 +from django.utils import timezone
3 +
4 +
5 +class Post(models.Model):
6 + author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
7 + title = models.CharField(max_length=200)
8 + text = models.TextField()
9 + created_date = models.DateTimeField(
10 + default=timezone.now)
11 + published_date = models.DateTimeField(
12 + blank=True, null=True)
13 +
14 + def publish(self):
15 + self.published_date = timezone.now()
16 + self.save()
17 +
18 + def __str__(self):
19 + return self.title
1 +h1 a {
2 + color: #FCA205;
3 + font-family: 'Lobster';
4 +}
5 +
6 +body {
7 + padding-left: 15px;
8 +}
9 +
10 +.page-header {
11 + background-color: #ff9400;
12 + margin-top: 0;
13 + padding: 20px 20px 20px 40px;
14 +}
15 +
16 +.page-header h1, .page-header h1 a, .page-header h1 a:visited, .page-header h1 a:active {
17 + color: #ffffff;
18 + font-size: 36pt;
19 + text-decoration: none;
20 +}
21 +
22 +.content {
23 + margin-left: 40px;
24 +}
25 +
26 +h1, h2, h3, h4 {
27 + font-family: 'Lobster', cursive;
28 +}
29 +
30 +.date {
31 + color: #828282;
32 +}
33 +
34 +.save {
35 + float: right;
36 +}
37 +
38 +.post-form textarea, .post-form input {
39 + width: 100%;
40 +}
41 +
42 +.top-menu, .top-menu:hover, .top-menu:visited {
43 + color: #ffffff;
44 + float: right;
45 + font-size: 26pt;
46 + margin-right: 20px;
47 +}
48 +
49 +.post {
50 + margin-bottom: 70px;
51 +}
52 +
53 +.post h1 a, .post h1 a:visited {
54 + color: #000000;
55 +}
...\ No newline at end of file ...\ No newline at end of file
1 +{% extends "base_generic.html" %}
2 +
3 +{% block content %}
4 +<p>Logged out!</p>
5 +
6 +<a href="{% url 'login'%}">Click here to login again.</a>
7 +{% endblock %}
...\ No newline at end of file ...\ No newline at end of file
1 +{% extends "base_generic.html" %}
2 +
3 +{% block content %}
4 +
5 +{% if form.errors %}
6 +<p>Your username and password didn't match. Please try again.</p>
7 +{% endif %}
8 +
9 +{% if next %}
10 + {% if user.is_authenticated %}
11 + <p>Your account doesn't have access to this page. To proceed,
12 + please login with an account that has access.</p>
13 + {% else %}
14 + <p>Please login to see this page.</p>
15 + {% endif %}
16 +{% endif %}
17 +
18 +<form method="post" action="{% url 'login' %}">
19 +{% csrf_token %}
20 +
21 +<div>
22 + <td>{{ form.username.label_tag }}</td>
23 + <td>{{ form.username }}</td>
24 +</div>
25 +<div>
26 + <td>{{ form.password.label_tag }}</td>
27 + <td>{{ form.password }}</td>
28 +</div>
29 +
30 +<div>
31 + <input type="submit" value="login" />
32 + <input type="hidden" name="next" value="{{ next }}" />
33 +</div>
34 +</form>
35 +
36 +{# Assumes you setup the password_reset view in your URLconf #}
37 +<p><a href="{% url 'password_reset' %}">Lost password?</a></p>
38 +
39 +{% endblock %}
...\ No newline at end of file ...\ No newline at end of file
1 +{% load staticfiles %}
2 +<html>
3 + <head>
4 + <title>Django Girls blog</title>
5 + <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
6 + <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
7 + <link href="//fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
8 + <link rel="stylesheet" href="{% static 'css/posts.css' %}">
9 + </head>
10 + <body>
11 + <div class="page-header">
12 + <h1><a href="/">Django Girls Blog</a></h1>
13 + </div>
14 + <div class="content container">
15 + <div class="row">
16 + <div class="col-md-8">
17 + {% block content %}
18 + {% endblock %}
19 + </div>
20 + </div>
21 + </div>
22 + </body>
23 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +{{files}}
...\ No newline at end of file ...\ No newline at end of file
1 +{% extends 'website/base.html' %}
2 +
3 +{% block content %}
4 + <div class="post">
5 + {% if post.published_date %}
6 + <div class="date">
7 + {{ post.published_date }}
8 + </div>
9 + {% endif %}
10 + <h1>{{ post.title }}</h1>
11 + <p>{{ post.text|linebreaksbr }}</p>
12 + </div>
13 +{% endblock %}
...\ No newline at end of file ...\ No newline at end of file
1 +{% extends 'website/base.html' %}
2 +
3 +{% block content %}
4 + {% for post in posts %}
5 + <div class="post">
6 + <div class="date">
7 + <p>published: {{ post.published_date }}</p>
8 + </div>
9 + <h1>
10 + <h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
11 + </h1>
12 + <p>{{ post.text|linebreaksbr }}</p>
13 + </div>
14 + {% endfor %}
15 +{% endblock %}
...\ No newline at end of file ...\ No newline at end of file
1 +from django.test import TestCase
2 +
3 +# Create your tests here.
1 +from django.conf.urls import url
2 +from website import views
3 +
4 +urlpatterns = [
5 + url(r'^$', views.post_list, name='post_list'),
6 + url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
7 + url(r'^files/', views.file_list, name='file_list'),
8 +
9 +]
...\ No newline at end of file ...\ No newline at end of file
1 +from django.shortcuts import render, get_object_or_404
2 +from django.utils import timezone
3 +from website.models import Post
4 +from restful.models import File
5 +
6 +
7 +
8 +# Create your views here.
9 +def post_list(request):
10 + posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
11 + return render(request, 'website/post_list.html', {'posts':posts})
12 +
13 +def file_list(request):
14 + files = File.objects.all()
15 + return render(request, 'website/file_list.html', {'files': files})
16 +
17 +def post_detail(request, pk):
18 + post = get_object_or_404(Post, pk=pk)
19 + return render(request, 'website/post_detail.html', {'post': post})