如何在网站中加入(嵌套)django应用程序 [英] How to join(nest) django apps in site

查看:107
本文介绍了如何在网站中加入(嵌套)django应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上次我通过python库 - django。我有一些MVC模型的工作原理以及关于创建django项目的其他基础知识。我要在django创建网站,但在我的脑海里有一件事情会变大。
在我创建管理文章,民意调查和其他可能更改网站内容的应用程序后,我必须在一个页面上加入。由于缺乏知识,对我来说看起来很糟糕。



为了创建索引页面,我介意创建应用程序并将其在URLconf中连接到'^ $ 。那么,我将拥有包含html - head,meta,includes(js,css)等内容中所有内容的大型模板。对我而言听起来并不好听(可能缺乏知识)。看看..



我将如何获得链接到网站上的具体内容(即文章),以给予某人?我需要 / article / 2013/02/55 显示具体的文章,但它需要使用我的索引页面的元,包括,整个网站的结构等。我无法想象我将如何能够连接在一起。



我正在Django的最终指南:Web开发完成一书中。也许我会得到答案,但我很紧张和不耐烦。在网站上使用ajax和一些jquery-ui将是非常好的,但我甚至无法想象如何使用嵌套应用程序进行静态网站!

解决方案

您只需延伸基本模板和使用块。



base.html



  ; HTML> 
< head>
< title> ...< / title>
< link rel =stylesheettype =text / csshref =...>
< script> ...< / script>
< / head>
< body>
{%block content%}
基本模板的内容
{%endblock content%}
< / body>
< / html>



appname / templatename.html



  {%extendsbase.html%} 

{%block content%}
应用模板中的内容替换其他内容
{ %endblock内容%}

请参阅文档以获取有关模板继承的更多信息。


Last time i make my way through python library - django. I have idea how MVC model works and other basics about creating django projects. I'm going to create site in django but there is one thing that loom large in my mind. After i will create apps for managing articles, polls, and other likely to change content of site, i have to join it together on one page. By lack of knowledge it looks awful for me.

To make index page, i mind to create app and connect it in URLconf to '^$'. Then, i will have large template containing everything in html - head, meta, includes(js, css) etc. It doesn't sounds good for me(probably lack of knowledge). Look..

How i will be able to get link to specific content on site(i.e. article) to give it to somebody? I need /article/2013/02/55 show specific article but it needs to use my index page for meta, includes, entire structure of site etc. I can't imagine how I will be able to connect it together.

I'm in the course of "The Definitive Guide to Django: Web Development Done Right" book. Maybe i will get answer later but I'm nervous and impatient. It would be great to make use of ajax and some jquery-ui on site but i can't even imagine how to do static site with nested apps!

解决方案

You just need to extend the base template and use blocks.

base.html

<html>
  <head>
    <title>...</title>
    <link rel="stylesheet" type="text/css" href="...">
    <script>...</script>
  </head>
  <body>
  {% block content %}
    Content from the base template
  {% endblock content %}
  </body>
</html>

appname/templatename.html

{% extends "base.html" %}

{% block content %}
  Content from the app template to replace other content 
{% endblock content %}

See the docs for more info on template inheritance.

这篇关于如何在网站中加入(嵌套)django应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆