简体   繁体   English

如何对 Django 网站中的应用程序进行分类

[英]how can I classify apps in a django website

I wanna create a website using django framework , I don't know how to divide the website into several apps... Help me.我想使用 django 框架创建一个网站,我不知道如何将网站分成几个应用程序...帮帮我。

In advance , thanks a lot by the way , I'm new to web development顺便说一下,非常感谢,我是网络开发的新手

Django works by matching a URL pattern to some code that you have written in views.py. Django 的工作原理是将 URL 模式与您在 views.py 中编写的某些代码进行匹配。

In your case, you are pointing the same pattern (^$) to two view methods.在您的情况下,您将相同的模式 (^$) 指向两个视图方法。 Django will stop when it finds a match, so when you switch the patterns around, it will always match the first entry in the list. Django 会在找到匹配项时停止,因此当您切换模式时,它将始终匹配列表中的第一个条目。

If you change your patterns to:如果您将模式更改为:

urlpatterns = patterns('',
        url(r'^/two$', 'myapp2.views.home2', name='home2'),
        url(r'^$', 'myapp1.views.home1', name='home1'),

Now when you type htt://localhost:8000/two home2 will be executed, and when you type http://localhost:8000/ home1 will be executed.现在当你输入htt://localhost:8000/two home2 将被执行,当你输入http://localhost:8000/ home1 将被执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM