I have tested django-startproject (https://github.com/lincolnloop/django-startproject). I have read their doc and Lincoln Loop best practice, but many of their choices are still unclear for me (the way they organize their folders, etc.).
Especially, I am quite confused by the way their bin/manage.py behave.
When I execute python bin/manage.py startapp Test, it creates the app, but instead of putting it in my project (or in apps), the directory is created in conf/local.
Is this the wanted behaviour ?
That's because django's manage.py is by default located at the root of the project, and by default the startapp function(which is not created by the lincolnloop guys) places the apps in the current folder (where manage.py is located). this is from the official docs:
startapp [destination]
django-admin.py startapp
Creates a Django app directory structure for the given app name in the current directory or the given destination.
you can explicitly specify where to place the app with the destination parameter.
Related
I am very New to Python web development ,so got confuse while learning ,when we create new Project with the command --django-admin startProject 'ProjectName'
It Created a project folder in my drive and then we create application in it suppose with the name of "calculator", we start working in it ,
but after some more requirement we have to create a new different Project with the Name of the Hrms so the question arise for this again we have to run the same command django-admin startProject 'ProjectName' and then we have to create application in it or we can create in it?
One project may have many application in it & you can create app using below code.
django-admin startapp my_new_app.
Also you can reuse same app in multiple projects.
For Hrm you should create new app instead of new project.
Example : One ERP projects may have many apps like hrm, sales, purchase, inventory etc.. & we can reuse same apps into another ERP projects also if needed.
Hope above clarifications works for you.
Project and apps and different see this
django-admin startproject mydjangoproject creates the project for you,
What you want to do is to create an app hrms and caculator can be apps living under umbrella of one project that is mydjangoproject
You should create apps here by django-admin startapp hrms and django-admin startapp calculator and add it to settings.py in your project folder
INSTALLED_APPS = [ #otherapps here
'hrms',
'calculator']
Start project and start app are very different commands. With the first one you create a project which will have a base structure to work on. The second command is used to create apps which you could classify as controllers. Each app will live in a folder where you will program the business logic and bind endpoints.
The app would be a new module in your project, let's say it would be a management system with human resources, financial modules, etc., so you would create an app for each of them to better organize, but nothing prevents creating everything in one app.Create a project only if it is something different.
what i'm trying to do is to change the default path for migrations for a specific application in a django project to put it outside the project itself but keeping it transparent, keeping use of makemigrations and migrate.
Is it possible? if yes, how?
Django has a MIGRATION_MODULES setting. It allows you to specify a different module for migrations per app. The module can be outside of the Django project, it just needs to be on your python path.
MIGRATION_MODULES = {'myapp': 'othermodule.db_migrations'}
I have tried searching around for this, but searches including "django", "app", and "namespace" all bring up topics mostly relating to URLConf, not what I want to know.
In Django settings, apps included in a project are listed in the INSTALLED_APPS setting. Most community-released apps are not "namespaced" in that the app name consists of only letters, numbers, and underscores. There are official apps like "django.contrib.sites" that are "namespaced" with dot-syntax. What I cannot seem to find is: how do I do this? For example, if I want to create an app like "mycompany.app". The startapp command of manage.py does not allow naming like this if I try ./manage.py "mycompany.app", complaining of invalid characters.
So what Python and/or Django magic am I missing to create and use apps in this way? Or is there some reason why doing this is discouraged, and I should only make apps like "mycompany_app"?
Create a python package mycompany (i.e. folder with init.py file inside), inside create package app.
There is also namespace term in django urls, can be noticed in calls like reverse('namespace:view-name'), here is the doc for these: https://docs.djangoproject.com/en/1.7/topics/http/urls/#url-namespaces
Imagine I have two or more apps in my django project, I was able to successfully write and execute custom manage.py commands when I had only one app, A.
Now I have a new app, B, and as mentioned in https://docs.djangoproject.com/en/dev/howto/custom-management-commands/ I created directory structure of B/manangement/commands and wrote a custom module.
When I run python manage.py , it keeps complaining Unknown command. However if I move this command to other app, i.e. to folder A/management/commands and then run python manage.py <command>, it works seamlessly.
Any idea how I can resolve this?
As #Babu said in the comments, It looks like you may not have added your app to INSTALLED_APPS in your settings.py.
It's also possible that you're missing the __init__.py files (that are required in python modules) from the management and commands folders.
Alternatively, (sorry to say this) you may have misspelt "management" or "commands", or even the name of the command you're running.
Most likely, you did not include app B in your settings.py
If you just run python manage.py with no command specified, it will print the list of commands Django can find.
This can help rule out misspelling the command name, but doesn't answer the question of whether or not you made management and commands both packages, or if app B simply isn't listed in your settings.INSTALLED_APPS
It looks like you have not registered your app B in INSTALLED_APPS in our settings.py.
You also need to add a __init__.py file in both folders(management and commands) to make it as a package. Make Sure you spell folder names correctly.
When including an app's URL's in the project's urls.py, my coding partner does it this way:
('^stops/', include('stops.urls'))
However, Django documentation specifies the following syntax:
('^clients/', include('project_name.app_name.urls'))
His way has worked. Is there a reason to specify the project name at all?
It depends on your PYTHONPATH setting and the structure of your projects and apps.
We have many, many projects. Each with several apps. All are on our PYTHONPATH, so the project name is essential.
If you have only one project, and the top-level project directory is on your PYTHONPATH, then each app can be resolved separately and you can't use the project name.
It also depends upon if the app is inside your project, or a reusable one.
I have a fresh virtualenv for every project, and use a separate mercurial repository for each app. These are then installed into the system path (either in editable form for development, or in non-editable form for deployment), meaning I have <appname> on the PYTHONPATH.
if on the shell you run
import this
you will see that there is a zen of python ''explicit is better than implicit'' hence thats the reason to specify the project name.