모든 테마 보이기

3194 단어
1.URL node2:/django/mysite/learning_log/learning_log#cat urls.py """learning_log URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/1.11/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import include,url from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^log/',include('learning_logs.urls',namespace='learning_logs')), ] topics/,Django URL . URL , URL topics, . : http://192.168.137.3:9000/log/topics node2:/django/mysite/learning_log/learning_logs#cat views.py # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.shortcuts import render from .models import Topic # Create your views here. def index(request): return render(request,'learning_logs/index.html') def topics(request): print 'call topics' topics = Topic.objects.order_by('date_added') context = {'topics':topics} return render(request,'learning_logs/topics.html',context) 。 topics() : Django request 。 。 , 。 3. context, topics() 。 , topics.html, index.html node2:/django/mysite/learning_log/learning_logs/templates/learning_logs#cat topics.html {% extends "learning_logs/base.html" %} {% block content %}

Topics

    {% for topic in topics %}
  • {{ topic }}
  • {% empty %}
  • No topics have been added yet.
  • {% endfor %}
{% endblock content %} index.html , {% extends %} base.html, content 。 , 。 2 , for , context topics. Python ; Python for , , for {% endfor %} 。 , , , 。 ,{{topic}} topic , Django 。 HTML
  • , {% empty %}, Django topics , , 。 for node2:/django/mysite/learning_log/learning_logs/templates/learning_logs#cat base.html

    Learning Log Topics

    {% block content %}{% endblock content %} http://192.168.137.3:9000/log/topics

  • 좋은 웹페이지 즐겨찾기