如何在Django中创建子应用程序? [英] How do I create sub-applications in Django?

查看:93
本文介绍了如何在Django中创建子应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Django的新手,但在编程方面经验丰富。我有一组相关的应用程序,我想分组到一个子应用程序,但不知道如何让manage.py为我做这个。



理想情况下,我最终会得到如下结构:

  project / 
app /
subapp1 /
subapp2 /

我尝试过 manage.py startapp应用程序.subapp1 manage.py startapp app / subapp1

但这告诉我 / 是应用程序名称的无效字符。



我已经尝试改成app目录,并运行 ../ manage.py subapp1 ,但这使supapp1在顶层。注意,我不想试图直接制作一个独立的应用程序。我试图从一个项目中做所有这些。

解决方案

你仍然可以这样做:

  cd app 
django-admin startapp subapp1

这将工作(创建应用程序基本结构),但是 app subapp1 将仍然被认为是两个不相关的应用程序,您必须将它们都添加到设置中的 INSTALLED_APPS



<这是否回答你的问题?否则,你应该更多地了解你正在努力做什么。


I'm a Django newbie, but fairly experienced at programming. I have a set of related applications that I'd like to group into a sub-application but can not figure out how to get manage.py to do this for me.

Ideally I'll end up with a structure like:

project/
   app/
       subapp1/
       subapp2/

I've tried manage.py startapp app.subapp1 and manage.py startapp app/subapp1
but this tells me that / and . are invalid characters for app names.

I've tried changing into the app directory and running ../manage.py subapp1 but that makes supapp1 at the top level. NOTE, I'm not trying to directly make a stand-alone application. I'm trying to do all this from within a project.

解决方案

You can still do this :

cd app
django-admin startapp subapp1

This will work (create the application basic structure), however app and subapp1 will still be considered as two unrelated applications in the sense that you have to add both of them to INSTALLED_APPS in your settings.

Does this answer your question ? Otherwise you should tell more about what you are trying to do.

这篇关于如何在Django中创建子应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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