Project Directory
===========
in terminal
--------------------
erp@erp-Pegatron:~/mysite$ tree
.
|-- blog
| |-- admin.py
| |-- admin.py~
| |-- admin.pyc
| |-- __init__.py
| |-- __init__.pyc
| |-- migrations
| | |-- 0001_initial.py
| | |-- 0001_initial.pyc
| | |-- __init__.py
| | `-- __init__.pyc
| |-- models.py
| |-- models.py~
| |-- models.pyc
| |-- templates
| | |-- archives.html
| | |-- archives.html~
| | |-- base.html
| | |-- base.html~
| | |-- blog.html
| | |-- blog.html~
| | |-- lastestnews.html
| | |-- post.html
| | `-- post.html~
| |-- tests.py
| |-- Untitled Document
| |-- urls.py
| |-- urls.py~
| |-- urls.pyc
| `-- views.py
|-- db.sqlite3
|-- images
| `-- hrm.JPG
|-- manage.py
`-- mysite
|-- __init__.py
|-- __init__.pyc
|-- settings.py
|-- settings.py~
|-- settings.pyc
|-- urls.py
|-- urls.py~
|-- urls.pyc
|-- wsgi.py
`-- wsgi.pyc
Codes for the templates
================
archieve.html
--------------
{% extends "base.html" %}
{% block content %}
<h2>Archives</h2>
{% for Post in object_list %}
<p>{{ post.date|date:"Y-m-d" }}<a href="/blog/{{ Post.id}}">{{ Post.title }}</a></p>
{% endfor %}
{% endblock %}
base.html
-------------
<!DOCTYPE html>
<html>
<body>
<img src="hrm.JPG" alt="Mountain View" style="width:304px;height:228px">
<div id="container" style="width:auto">
<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">N-HRM</h1></div>
<div id="menu" style="background-color:#FFD700;height:500px;width:150px;float:left;">
<b>Links</b><br>
<a href="">Login</a><br>
<a href="">Registration</a><br>
</div>
<div id="content" style="background-color:#EEEEEE;height:500px;width:779px;float:left;">
<table>
{% block content %}
{% endblock %}
</td>
</table>
</div>
<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
Copyright © ninfosoft.com</div>
</div>
</body>
</html>
blog.html
------------
{% extends "base.html" %}
{% block content %}
{% for Post in object_list %}
<h3><a href="/blog/{{ Post.id}}">{{ Post.title }}</a></h3>
<div class="post_meta">
{{ post.date }}
</div>
<div class = "post_body">
{{ Post.body|safe|linebreaks}}
</div>
{% endfor %}
{% endblock %}
post.html
---------
{% extends "base.html" %}
{% block content %}
<h3><a href="/blog/{{post.id}}">{{post.title}}</h3>
<div class = "post_meta">
{{ post.date}}
</div>
<div class = "post_body">
{{ post.body|safe|linebreaks}}
{% endblock %}
model.py(in blog folder)
-----------
from django.db import models
class Post(models.Model):
title = models.CharField(max_length =140)
body = models.TextField()
date = models.DateTimeField()
def __unicode__(self):
return self.title
urls.py(in blog folder)
-------------
from django.conf.urls import patterns, include, url
from django.views.generic import ListView, DetailView
from blog.models import Post
urlpatterns = patterns('',
url(r'^$', ListView.as_view(
queryset=Post.objects.all().order_by("-date")[:10],
template_name="blog.html")),
url(r'^(?P<pk>\d+)$', DetailView.as_view(
model=Post,
template_name="post.html")),
url(r'^archives/$', ListView.as_view(
queryset=Post.objects.all().order_by("-date"),
template_name="archives.html")),
url(r'^latestnews/$', ListView.as_view(
queryset=Post.objects.all().order_by("-date")[:5],
template_name="latestnews.html")),
)
admin.py
------
from django.contrib import admin
from blog.models import Post
admin.site.register(Post)
urls.py(in mysite folder)
------------
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
===========
in terminal
--------------------
erp@erp-Pegatron:~/mysite$ tree
.
|-- blog
| |-- admin.py
| |-- admin.py~
| |-- admin.pyc
| |-- __init__.py
| |-- __init__.pyc
| |-- migrations
| | |-- 0001_initial.py
| | |-- 0001_initial.pyc
| | |-- __init__.py
| | `-- __init__.pyc
| |-- models.py
| |-- models.py~
| |-- models.pyc
| |-- templates
| | |-- archives.html
| | |-- archives.html~
| | |-- base.html
| | |-- base.html~
| | |-- blog.html
| | |-- blog.html~
| | |-- lastestnews.html
| | |-- post.html
| | `-- post.html~
| |-- tests.py
| |-- Untitled Document
| |-- urls.py
| |-- urls.py~
| |-- urls.pyc
| `-- views.py
|-- db.sqlite3
|-- images
| `-- hrm.JPG
|-- manage.py
`-- mysite
|-- __init__.py
|-- __init__.pyc
|-- settings.py
|-- settings.py~
|-- settings.pyc
|-- urls.py
|-- urls.py~
|-- urls.pyc
|-- wsgi.py
`-- wsgi.pyc
Codes for the templates
================
archieve.html
--------------
{% extends "base.html" %}
{% block content %}
<h2>Archives</h2>
{% for Post in object_list %}
<p>{{ post.date|date:"Y-m-d" }}<a href="/blog/{{ Post.id}}">{{ Post.title }}</a></p>
{% endfor %}
{% endblock %}
base.html
-------------
<!DOCTYPE html>
<html>
<body>
<img src="hrm.JPG" alt="Mountain View" style="width:304px;height:228px">
<div id="container" style="width:auto">
<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">N-HRM</h1></div>
<div id="menu" style="background-color:#FFD700;height:500px;width:150px;float:left;">
<b>Links</b><br>
<a href="">Login</a><br>
<a href="">Registration</a><br>
</div>
<div id="content" style="background-color:#EEEEEE;height:500px;width:779px;float:left;">
<table>
{% block content %}
{% endblock %}
</td>
</table>
</div>
<div id="footer" style="background-color:#FFA500;clear:both;text-align:center;">
Copyright © ninfosoft.com</div>
</div>
</body>
</html>
blog.html
------------
{% extends "base.html" %}
{% block content %}
{% for Post in object_list %}
<h3><a href="/blog/{{ Post.id}}">{{ Post.title }}</a></h3>
<div class="post_meta">
{{ post.date }}
</div>
<div class = "post_body">
{{ Post.body|safe|linebreaks}}
</div>
{% endfor %}
{% endblock %}
post.html
---------
{% extends "base.html" %}
{% block content %}
<h3><a href="/blog/{{post.id}}">{{post.title}}</h3>
<div class = "post_meta">
{{ post.date}}
</div>
<div class = "post_body">
{{ post.body|safe|linebreaks}}
{% endblock %}
model.py(in blog folder)
-----------
from django.db import models
class Post(models.Model):
title = models.CharField(max_length =140)
body = models.TextField()
date = models.DateTimeField()
def __unicode__(self):
return self.title
urls.py(in blog folder)
-------------
from django.conf.urls import patterns, include, url
from django.views.generic import ListView, DetailView
from blog.models import Post
urlpatterns = patterns('',
url(r'^$', ListView.as_view(
queryset=Post.objects.all().order_by("-date")[:10],
template_name="blog.html")),
url(r'^(?P<pk>\d+)$', DetailView.as_view(
model=Post,
template_name="post.html")),
url(r'^archives/$', ListView.as_view(
queryset=Post.objects.all().order_by("-date"),
template_name="archives.html")),
url(r'^latestnews/$', ListView.as_view(
queryset=Post.objects.all().order_by("-date")[:5],
template_name="latestnews.html")),
)
admin.py
------
from django.contrib import admin
from blog.models import Post
admin.site.register(Post)
urls.py(in mysite folder)
------------
from django.conf.urls import patterns, include, url
from django.contrib import admin
urlpatterns = patterns('',
url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
)
No comments:
Post a Comment