Adding a second project to a Django project - python

I'm new to Django. I'm using Django with Eclipse. I've created a Django project using Eclipse (called "Django_Test_Project"). I've also created a PyDev project outside of Eclipse, using the command line (called "polls"). It has models.py, views.py, and tests.py.
I created "polls" using the following command:
manage.py startapp polls
I want use Eclipse to add "polls" as a second project to "Django_Test_Project". How do I do that with a project that was created outside of Eclipse? Eclipse doesn't recognize "polls" as a project, probably because the project files are missing in "polls".
Any help is appreciated. Thanks.

You are working on the Django tutorial, right? First of all, your terminology is not correct. You confuse a project with an application or app for short. It's no surprise that Eclipse doesn't recognize polls as a project, because it's not a project but an app.
In Django 1.4.1, the standard structure for a project called mysite is this:
mysite/
manage.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
Your polls app should go in the same directory where the file manage.py is located:
mysite/
manage.py
polls/
__init__.py
models.py
tests.py
views.py
mysite/
__init__.py
settings.py
urls.py
wsgi.py
You can just move the polls directory into the mysite directory using the Windows Explorer, Finder, Terminal etc. (depends on which OS you are running on). After refreshing the project view in Eclipse, your polls app should show up. In any case, you should read the Django tutorial more carefully as it basically answers your question already.
Additionally, take a look at this thread that explains the difference between projects and apps in a bit more detail.

Related

How to add a folder to Django?

So my question looks like this
Creating a new project
django-admin startproject firstapp
Creating a new app
python manage.py startapp blog
So, my question is . I've added a new folder called "projects" within the app "blog"
Django doesn't see the folder. How to connect? via INSTALLED_APPS (I've tried it doesn't work)

Where is "views.py"

Him I am trying to set up my first django project. I have never done Django before so I don't know anything about it. I am trying to follow the official Django tutorial page, it tells me to open views.py. I can't find it anywhere in my "mysite" folder. In it, I have manage.py , db.sqlite3, __init__.py, settings.py, urls.py and wsgi.py along with the pycache folder, but no signs of views.py. Can anyone help me?
Running this command in console django-admin startproject myfirstproject will create a new django project for you, which will have another sub-folder named same as your project name. By default on creating a new project, the views.py file isn't created you have to create it manually in your project sub-folder.
To create a new app, Run django-admin startapp myapp which will create a new sub-folder under your parent directory which will have views.py where you can write your own custom views for your HTML templates

how to run django-simple-blog?

How to run Django-simple-blog? I tried to install django-simple-blog but could not find the manage.py file to run it. Can I get a solution or another simple blog?
Django has a concept of apps and a concept of projects. A project will have a manage.py file like you mention, and will also have a settings.py file that declares all of the apps that the project uses.
django-simple-blog is an app, meaning you install it within an existing project. After this explaination, the rest of the steps found here should be easier to follow: https://github.com/drager/django-simple-blog/blob/master/README.rst
The remaining steps are to:
Add 'simpleblog' to INSTALLED_APPS in your settings.py file
run the command python manage.py migrate from your project root
include 'simpleblog.urls' into any of your urls.py file

Pinax Structure

I have just installed the Pinax but i'm very confused now.
in my structre
i have two directories
mysite and mysite-env
I dont why i have two directories. I just followed the installitation directions
in mysite,
<project-root>
apps/
__init__.py
deploy/
__init__.py
fcgi.py
wsgi.py
fixtures/
initial_data.json
locale/
...
requirements/
base.txt
project.txt
sitemedia/static // I move static file from mysite-env to here
...
templates/
_footer.html
homepage.html
site_base.html
__init__.py
manage.py
settings.py
urls.py
However,
default index page is in mysite-env/lib/python2.6/site-packages/pinax_theme_bootstrap/templates/banner_base.html
Should i manage my site from mysite ?
Pinax uses virtualenv to prevent messing up your local python libs by your project dependency.
So, launch the site with $ source mysite-env/bin/activate it will be fine. If you really hate mysite-env, just skip the virtualenv part.

In which cases can I reuse a django project for multiple applications?

I just finished doing the tutorial django app. I now want to build my own app. Should I just create a new app within the tutorial project folder or should I create a new project folder with a new app?
I am unsure in which cases it makes sense to re-use a project and create multiple apps under that project vs. making new projects for each new app
You don't need to create a project for each app. When you create a project, you can define new apps inside a project if you want, in fact the manage.py inside the project folder is the same as the django-admin.py outside. So you can startapp directly using django-admin.py:
$ django-admin.py startproject foo
$ django-admin.py startapp bar
$ ls foo bar/
bar/:
__init__.py models.py tests.py views.py
foo:
__init__.py manage.py settings.py urls.py
A website is usually a project. In that website, you may have multiple features (a blog, a wiki, etc.). Each of those features should be an application in the project.

Categories