django:view

hide@deb1:~/dj/cats$ vi urls.py

 
from django.conf.urls.defaults import *

urlpatterns = patterns('',
    # Example:
    # (r'^cats/', include('cats.apps.foo.urls.foo')),
    (r'^cats/$',  'jellicle.views.index'),

    # Uncomment this for admin:
     (r'^admin/', include('django.contrib.admin.urls')),
)

hide@deb1:~/dj/cats$ python manage.py runserver 0.0.0.0:8000

WS000000 

hide@deb1:~/dj/cats$ vi jellicle/views.py

# Create your views here.

from django.http import HttpResponse

def index(request):
  return HttpResponse("What's a Jellicle Cat ?")

WS000001

hide@deb1:~/dj/cats$ vi urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns(”,
    # Example:
    # (r’^cats/’, include(‘cats.apps.foo.urls.foo’)),
    (r’^cats/$’                   ,’jellicle.views.index’),
    (r’^cats/(?P<cat_id>\d+)/$’   ,’jellicle.views.detail’),

    # Uncomment this for admin:
     (r’^admin/’, include(‘django.contrib.admin.urls’)),
)

WS000002

hide@deb1:~/dj/cats$ vi settings.py

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates".
    # Always use forward slashes, even on Windows.
   '/home/hide/dj/cats/templates'
)

hide@deb1:~/dj/cats$ mkdir -p templates/cats
hide@deb1:~/dj/cats$ vi templates/cats/index.html

<h1>The Jellicle Tribe</h1>


hide@deb1:~/dj/cats$ vi jellicle/views.py

from django.template import Context, loader
from django.http import HttpResponse

def index(request):
  t = loader.get_template('cats/index.html')
  c = Context({})
  return HttpResponse(t.render(c))

WS000003

 

hide@deb1:~/dj/cats$ vi jellicle/views.py

from django.template import Context, loader
from django.http import HttpResponse
from jellicle.models import Cat

def index(request):
  cat_list = Cat.objects.all().order_by('-updatedt')[:10]
  t = loader.get_template('cats/index.html')
  c = Context({
    'cat_list': cat_list,
  })
  return HttpResponse(t.render(c))

hide@deb1:~/dj/cats$ vi templates/cats/index.html

<h1>The Jellicle Tribe</h1>

{% if cat_list %}
    <ul>
        {% for cat in cat_list %}
                <li>{{ cat.name}}</li>
        {% endfor %}
    </ul>
{% else %}
    <p>No jellicle is available.</p>
{% endif %}

WS000004

hide@deb1:~/dj/cats$ vi jellicle/views.py

 

from django.shortcuts import render_to_response 

from jellicle.models import Cat

def detail(request, cat_id):
  cat_item = Cat.objects.get(pk=cat_id )
  return render_to_response('cats/detail.html',
                                  {'cat_item': cat_item}) 

hide@deb1:~/dj/cats$ vi templates/cats/detail.html

<h1>The Jellicle</h1>
{% if cat_item%}
  {{ cat_item.name}}<br>
  {{ cat_item.description }} <br>
{% else %}
  <p>No !</p>
{% endif %}
WS000005 

hide@deb1:~/dj/cats$ vi templates/cats/index.html

<h1>The Jellicle Tribe</h1>

{% if cat_list %}
    <ul>
        {% for cat in cat_list %}
                <li><a href="./{{ cat.id }}/">{{ cat.name}}</a></li>
        {% endfor %}
    </ul>
{% else %}
    <p>No jellicle is available.</p>
{% endif %}

hide@deb1:~/dj/cats$ vi templates/cats/detail.html

<h1>The Jellicle</h1>
{% if cat_item%}
  {{ cat_item.name}}<br>
  {{ cat_item.description }} <br>
{% else %}
  <p>No !</p>
{% endif %}
<hr>
<a href="../">Jellicles</a>

WS000006 WS000007

カテゴリー: 未分類 パーマリンク

django:view への2件のフィードバック

  1. Unknown より:

    Hi,Do you need mp4 advertisement players, SD card players and advertisement LCD displays? Please go Here:www.amberdigital.com.hk(Amberdigital).we have explored and developed the international market with professionalism. We have built a widespread marketing network, and set up a capable management team dedicated to provide beyond-expectation services to our customers.
    amberdigital Contact Us
    E-mail:sstar@netvigator.com
    website:www.amberdigital.com.hk
    alibaba:amberdigital.en.alibaba.com[efhffcdiaadghd]

  2. Unknown より:

    Hi,Do you have second hand lcds, used laptop lcds and used LCD displays? Please go here:www.sstar-hk.com(Southern Stars).We are constantly buying re-usable LCD panels.We recycled LCDs.The re-usable panels go through strictly designed process of categorizing, checking, testing, repairing and refurbishing before they are re-used to make remanufactured LCD displays and TV sets.Due to our recent breakthrough in testing and repairing technology of LCD, we can improve the value for your LCD panels.
    website:www.sstar-hk.com[dgfhfdjcjhdggeg]

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中