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
Related
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)
So, I am learning Django using Django By Example book.
I moved to a new chapter where I needed to make a new project and app. This is what I did.
django-admin startproject myshop
cd to myshop directory
django-admin startapp shop
python manage.py migrate
I am unable to migrate with the following error:
django.db.migrations.exceptions.NodeNotFoundError: Migration django.db.migrations.exceptions.NodeNotFoundError: Migration auth.0009_user_following dependencies reference nonexistent parent node (u'account', u'0002_contact')
I did make Contact model in account app in my last project.
How is the new project related to the old one?
Please help me resolve this problem. Thanks.
It means that you don't have the file 0002_contact in your account app's migration folder. You need to recover the file or configure this file 0009_user_following and remove the (u'account', u'0002_contact') line
I'm following the django tutorial, and I don't understand why put the templates folder for the admin pages in the base directory, instead of having it in mysite directory.
In fact, when adding templates to the polls app, these were put in the polls directory. Is there an underlying reason for this to happen? Will I run into trouble if I change this configuration?
An issue I ran into once with putting templates in apps’ template directories was that the template loader would use the first template it found by looping through the INSTALLED_APPS setting, so if your app comes after the admin app in the list (which it probably does), templates overriden there won’t be used.
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.
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.