Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Is it possible to create a model without an app?

I am new to Django, so i don't know if the answer is obvious. I created models.py inside a project and when i tried syncDB, it did not create the tables defined in models.py. Only when i create models.py inside an app and after registering the app with INSTALLED_APPS, the tables are getting created on syncDB.

Is this is how Django works? Or am i missing something.

like image 864
shanmuganathan Avatar asked Dec 06 '11 22:12

shanmuganathan


People also ask

Is it necessary to create app in Django?

Both sources agree that you should create a separate app in the following situations: If you plan to reuse your app in another Django project (especially if you plan to publish it for others to reuse). If the app has few or no dependencies between it and another app.

Can you use Django without models?

Yes that is possible, but a lot of ways how Django can help with webdevelopment are based on its models. For example based on a model Django can make a ModelForm [Django-doc] to automate rendering HTML forms that map to the model, validating user input, and saving it to the database.

What is the point of Django apps?

What is Django? Django is a high-level Python web framework that enables rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel.


1 Answers

Django only syncs what's defined in INSTALLED_APPS. The name is pretty straight-forward. Django's going to look for at least a module (directory with an __init__.py) with a models.py file inside. So yes, you need an "app", but that app can be just a directory with just __init__.py and models.py files inside.

like image 57
Chris Pratt Avatar answered Oct 26 '22 00:10

Chris Pratt