Django项目控制台管理+ Eclipse中的编码 [英] Django project console management + Coding in Eclipse

查看:225
本文介绍了Django项目控制台管理+ Eclipse中的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我真的很想使用控制台这样的东西,比如: p>


  • 管理一些项目的设置(例如运行之前)

  • 版本控制

  • 从模板创建项目



我知道我与Django我可以做这样的事情:



django-admin startproject,manage.py runserver,甚至更多



但是对于编码,我更喜欢使用Eclipse而不是console(vim:



所以我想将已经创建的项目导入Eclipse。



导入项目选项不'将我的项目的文件夹识别为有效的文件夹进行导入(可能是因为它没有.eclipse_project文件)。



我可以这样做New->项目 - >选择我的项目的文件夹作为我想要开始的内容。



这实际上是工作,但是令我烦恼的是,我甚至不能添加一个PyDev模块到这个项目,因为没有源文件夹,即使我有一个文件夹与
__init__.py内部的模块。执行此举之后的项目结构如下:

  mysite 
manage.py
/ mysite< - 被PyDev认为不是源文件夹
__init__.py
urls.py
settings.py
wsgi.py

我可以在项目的根文件夹中创建源文件夹,然后将mysite / mysite的内容移动到其中,但是:




  • 我不会在Django项目的结构中打破某些东西?

  • 每次创建django项目时,我不想这样做? li>
  • 有没有选择将/ mysite文件夹的类型更改为源文件夹?



我是做错事



我还尝试使用以下方式创建Django项目:



New-> Django project->我是获得相同的结构,或者没有源文件夹



btw。什么是推荐的django项目的结构?

解决方案

我使用Eclipse作为我的Django编码环境,你不需要源夹。只需使用Django提供的文件夹结构。 init .py显示了这个文件夹实际上是一个python模块的python。



命令 django-admin.py startproject myproject 将默认创建一个新目录'myproject'(=让它称之为项目工作区文件夹),其中包含一个manage.py和一个项目包文件夹(也称为myproject,其中包含一个settings.py和其他文件)。



您可以根据需要重命名项目工作区文件夹,但不会更改任何内容。不要重命名项目包(除非你知道你在做什么),因为settings.py正在引用该文件夹或者正好引用了这个模块。



创建您的文件夹结构,转到Eclipse并创建一个新项目,选择项目工作区文件夹,并准备就绪。



这是一个非常轻量级的安装程序,您无法运行任何django命令从Eclipse这样。然而,我建议使用终端/控制台来运行Django命令,因为它非常方便。



为了使Eclipse能够从一个文件跳转到另一个文件使用方法或类似的命令cmd + mouseclick,您必须将项目工作区文件夹包含在Eclipse中的系统PYTHONPATH 中。只需转到E clipse - 首选项 - PyDev - 解释器Python ,并通过按钮新建文件夹添加您的文件夹。见下面的屏幕截图:





我还可以推荐Django 文本编辑器插件为Eclipse。


I am trying to set up my first project in Django in the most comfortable way for me.

I really like to use console for such thing like :

  • managing some project's settings ( before running for instance )
  • version control
  • creating project from a template

I know I with Django I can do such thing with :

django-admin startproject, manage.py runserver and probably even more

But for coding I prefer to use Eclipse than console ( vim :P ).

So I want to import that already created project into Eclipse.

Import project option doesn't recognize my Project's folder as a valid folder for importing ( probably, because it has no file like .eclipse_project in it ).

I can do it this way New->Project-> select my Project's folder as the content I want to start with.

This actually works, but the thing that annoys me is that I can't add even one single PyDev module to this project, because there are no source folders, even though I have one folder with module called __init__.py within. The project structure after executing this move is following :

mysite
   manage.py
   /mysite                  <- considered by PyDev not as source folder
        __init__.py
        urls.py
        settings.py
        wsgi.py

I could create source folder in the Project's root folder and then move the content of mysite/mysite into it, but :

  • Won't I break something in Django project's structure?
  • I don't want to do that everytime I create a django project?
  • Is there an option to change type of that /mysite folder to source folder ?

Am I doing something wrong?

I also tried an option to create Django project using :

New->Django project-> I am getting the same structure, which either doesn't have source folder

btw. what is the recommended django project's structure ?

解决方案

I'm using Eclipse as my Django coding environment and you do not need a source folder. Just use the folder structure as it is provided by Django. The init.py shows python that this folder is actually a python module.

The command django-admin.py startproject myproject will by default, create a new directory 'myproject' (=lets call it the project workspace folder) which contains a manage.py and a project package folder (also named 'myproject', containing a settings.py and other files).

You can rename the project workspace folder as you want, it does not change anything. Do not rename the project package (unless you know what you do), as the settings.py is referencing to this folder or exactly, is referencing to this module.

Having created your folder structure, go to Eclipse and create a new project selecting the project workspace folder, and you are ready.

This is a very lightweight setup, and you cannot run any django commands from Eclipse this way. Nevertheless I would recommend using the terminal / console for running Django commands, as it is very handy.

In order that Eclipse will be able to jump from one file to the other, using the command "cmd + mouseclick" on a method or similar, you have to include your project workspace folder into the system PYTHONPATH in Eclipse. Just go to Eclipse - Preferences - PyDev - Interpreter Python and add your folder via the button New Folder. See screenshot below:

I can also recommend the Django text editor plugin for Eclipse.

这篇关于Django项目控制台管理+ Eclipse中的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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