I new in django, but I am really old in web developpement.
My question is about how to properrly organize your project into a django project. I am about to build my first web site in django and i have the following question :
I want a contact page in my website? basically it's a form/view/template, but where do I create that ? should I create a whole new app?
Django projects deliver functionality through apps. A project is the configuration holding your chosen apps together. It's highly likely you'll need to write at least one app yourself. Your app will have models, views and forms.
There are a number of projects that can help bootstrap your project. See the matrix on djangopackages.com related to boostrapping.
Pinax is a good application bootstrapping tool providing a standard project layout, starter projects, reusable apps and default templates.
The authors of Two Scoops of Django have a layout on GitHub which is focused on the environment and file/directory layout.
Related
I am currently developing a mobile app using Ionic and I am using Django Admin Interface as sort of Backend for adding and editing the content of my mobile app through a MySQL Database.
I currently wish to create a custom analytical dashboard for tracking the usage of the users of my mobile app in the startpage of the Django Admin. While there are some analytical packages for tracking the usage in Django, they only function for web applications.
In my case I need to gather and display aggregate data from my database (Django models & not Django models) as well for other APIs. Is there a way how can I fetch data in form of SQL queries and display them in my dashboard using Python (Django)?
And how can I extend the starting page of Django Admin to a full analytical dashboard with the named functionalities?
I am currently struggling with this as I am new to Django. Any help is much appreciated!
There are some prebuilt admin themes which you can look into, and I personally recommend Django Jet. You can also change directly the way that the admin templates are made and rendered looking around the contrib/admin folder on your Django installation, or you can extend the admin views and templates, take a look at the documentation. Hope I could help!
I am learning Django after moving from J2EE (Java). I have a problem with Django project layout following MVC pattern.
In J2EE, my project includes 3 main parts:
Model:
JavaBean (DTO): defines classes based on Database tables.
DAL: defines classes to manipulate java beans with database.
Controller:
Servlets
View:
JSP files
Therefore, I have 3 packages(DTO,DAL,Controller) and a folder containing JSP files.
I understand that Django uses MTV. However, there's a submodule of a Django project called "app" that contains "model" and "view" inside. This makes me confused when following project layout according to J2EE above.
Hope to receive some advises from you guys. Thank you.
The difference between a project and an app, an app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular website. A project can contain multiple apps. An app can be in multiple projects.
In django , a project is a container consists of multiple apps that each app has its own model view and controller.
for example your project can have blog and news apps.you can imagine that your java mvc application has been grouped to several apps.
go to each app's folder(you have named the first app , app) define your model in model.py and views...
i´m quite new to django. My question is probably very simple but i´m struggling on what is the best approach. I am trying to develop a web platform for work. It is supposed to have a homepage that shows four different services. By clicking in one of those services a login page should be displayed entering what i think it should be a different project because it is going to have their own views, users and database. The question is how do i build a homepage like this? What is the best approach? If having four django projects in a homepage is the way how do i do that?
I'm trying to create a new Django/Python project in the JetBrains PyCharm IDE.
However, while typing my software name it informs me that
"You cannot call your app the same as your project".
Trying to fully understand the distinction between projects and applications in Django, I'd love someone to demonstrate the difference between an application and a project for some known compounded websites like Facebook, Gmail and YouTube.
My try with Facebook:
facebook
users
messages
notifications
posts
...
Basically the gist is that an app represents a specific part of your whole project. Moreover, the app can be "pluggable" into a similar project. In order to be maintainable an app should have it's own objectives that differ from the objectives of other apps.
In the excellent "Two Scoops of Django" book, the authors quote James Bennett:
The art of creating and maintaining a good Django app is that it
should follow the truncated Unix philosophy according to Douglas
McIlroy: "Write programs that do one thing and do it well".
Again the authors state:
In essence, each app should be tightly focused on its task. If an app
can’t be explained in a single sentence of moderate length, or you
need to say ‘and’ more than once, it probably means the app is too big
and should be broken up.
Update 19/12/2014:
With Django 1.7 this description of "Projects and applications" is definitely worth reading.
Update 21/12/2017:
Django 1.10 link here.
from the tutorial in the docs:
Projects vs. apps
What’s the difference between a project and an app? An app is a Web application that does something – e.g., a Weblog system, a database of public records or a simple poll app. A project is a collection of configuration and apps for a particular Web site. A project can contain multiple apps. An app can be in multiple projects.
https://docs.djangoproject.com/en/dev/intro/tutorial01/#creating-models
If you compared it to youtube the whole youtube site could be one big project, with functionality divided in apps such as the video search, messaging, profile/channel creation...if the structure is simpler you can keep different parts in one place, that's up to you. I prefer to only start splitting stuff up down the road.
In the official Django documentation:
1) An application is a web application that does something, for example, a blog system
2) A project is a collection of configuration and applications for a particular web site
3) A project can contain multiple applications. An application can be in multiple projects.
An application can be anything that can do some specific task in website. Ex:Banking domain -> Loan application, credit/debit card application etc.
A project is a collection of applications for a particular web site. Ex: Banking software, Gmail, Facebook etc.
Refer : https://consideratecode.com/2017/12/29/django-app-project-site/
After reading through How do you divide your project into applications in Django? and Django documentation about applications I am still not sure whether I should make or not a new application for certain stuff.
Let's imagine I have a Website with the following sections: <Home> <Login> <Register> <My account>.
Should all them be different applications? or should they be just one?
Also, imagine I include a section <Wiki> but it is not very linked with the page (I mean, not the design but the content makes relation to it).
Would this be a new project or application?
The individual sets of functionality (such as the ones you listed) should be applications.
When you group several applications together, you form a project.
However, the individual applications are usually self-contained enough that they could be picked up and dropped into another application. In this manner, you can re-use your 'login' application in several projects.
If it's part of the same site or webapp you're building, than don't make another project, one project shares the same settings.py, for example, so you can imagine that everything that relates to it belongs to the same project.
About the apps, you can create an entire project with just one app, but that's not advisable, you can separate your models in apps in a way that you fell confortable with it, for your own organization.
About login/register, take a look on User authentication documentation, that can clarify a little how one part of the site, in this case, authentication, can work with it's own app.
You should also do the Tutorial which could help you to understant how django basically works.