Skip to content

Commit af014d2

Browse files
committed
implement base for views
1 parent 7dfc9f2 commit af014d2

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

tutorial/apps/blog/forms.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# -*- coding: utf-8 -*-
2+
from django import forms
3+
from apps.blog import models
4+
5+
6+
class PostForm(forms.ModelForm):
7+
class Meta:
8+
model = models.Post
9+
exclude = ['last_change']

tutorial/apps/blog/urls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
urlpatterns = patterns(
66
'',
77
url(r'^$', views.home, name='home'),
8-
url(r'^posts/$', views.post_list, name="post_list"),
9-
url(r'^post/(?P<id>\d+)/$', views.post_detail, name="post_detail"),
10-
url(r'^edit-post/$', views.post_form, name="post_form"),
11-
url(r'^edit-post/(?P<id>\d*)/$', views.post_form, name="post_form"),
8+
#url(r'^posts/$', views.post_list, name="post_list"),
9+
#url(r'^post/(?P<id>\d+)/$', views.post_detail, name="post_detail"),
10+
#url(r'^edit-post/$', views.post_form, name="post_form"),
11+
#url(r'^edit-post/(?P<id>\d*)/$', views.post_form, name="post_form"),
1212
)

tutorial/apps/blog/views.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1-
from django.shortcuts import render
1+
# -*- coding: utf-8 -*-
2+
from django.shortcuts import render_to_response
3+
from django.shortcuts import RequestContext
4+
from django.shortcuts import get_object_or_404
5+
from django.http import HttpResponseRedirect
6+
from django.core.urlresolvers import reverse
27

3-
# Create your views here.
8+
from apps.blog import models
9+
from apps.blog import forms
10+
11+
12+
def home(request):
13+
return render_to_response(
14+
"blog/home.html",
15+
context_instance=RequestContext(request)
16+
)

tutorial/templates/blog/home.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html lang="es">
3+
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
</head>
9+
10+
<body>
11+
12+
<h1> HOLA MUNDO </h1>
13+
14+
</body>
15+
16+
</html>
17+

tutorial/tutorial/settings.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
"""
1010

1111
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12-
import os
13-
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
12+
from unipath import Path
1413

1514

15+
BASE_DIR = Path(__file__).ancestor(2)
16+
print BASE_DIR
17+
1618
# Quick-start development settings - unsuitable for production
1719
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/
1820

@@ -26,6 +28,25 @@
2628

2729
ALLOWED_HOSTS = []
2830

31+
TEMPLATE_CONTEXT_PROCESSORS = (
32+
'django.contrib.auth.context_processors.auth',
33+
'django.core.context_processors.debug',
34+
'django.core.context_processors.i18n',
35+
'django.core.context_processors.media',
36+
'django.core.context_processors.static',
37+
'django.core.context_processors.tz',
38+
'django.contrib.messages.context_processors.messages',
39+
'django.core.context_processors.request',
40+
)
41+
42+
TEMPLATE_LOADERS = (
43+
'django.template.loaders.filesystem.Loader',
44+
'django.template.loaders.app_directories.Loader',
45+
)
46+
47+
TEMPLATE_DIRS = (
48+
BASE_DIR.child("templates"),
49+
)
2950

3051
# Application definition
3152

@@ -59,7 +80,7 @@
5980
DATABASES = {
6081
'default': {
6182
'ENGINE': 'django.db.backends.sqlite3',
62-
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
83+
'NAME': 'db.sqlite3',
6384
}
6485
}
6586

0 commit comments

Comments
 (0)