Including an existing Python program in a Django site

I need to convert an existing python desktop application to a Django dedicated website. To do this, I will probably have several Django applications, each one performing specific functions.

What I'm not sure about is where to put all the existing python files for each application. Each application will require several existing python files. For a main Django application, most of the program logic will be in views.py. However, the desktop app I will be converting is great with a few python files. In other words, I can't just dump the entire app into the views.py file of the Django app.

My thinking is that inside views.py I would be calling various existing python files stored in a subdirectory. I'm just not sure what is the best fit for where to put all these files? Can I just create a new folder in the application, for example called "program" that will contain all the python files.

I am assuming the files should not go into statics because this needs to be used for pdf, css, etc.? Should it be possible to enter templates?

Just trying to figure it out is usually done. Let me know if I haven't explained myself enough. Thank.

+3


source to share


3 answers


First of all, you can make modules views.py

, models.py

etc. instead of separate files. You can also add other modules such as core

, helpers

you name it to contain the business logic code, which is not necessarily a view.

For example, my relatively large django application has the following structure:



my_app
  views
    __init__.py
    example_view_1.py
    example_view_2.py
    some_module
      __init__.py
      another_view.py
    ...
  models
    (all my app models)
  helpers
    (helper modules)
  backends
    (authentication backends)
  forms
    (django forms)

third_party
  (all third party packages - I use GAE so I must upload them)

      

+2


source


It depends on what you include in your project. The naming convention has agreements, such as views.py

, models.py

, admin.py

, standard stuff, but then there are add-ons to packages that you import into the project through the settings (for example, tasks.py

for Celery ).

It all depends on the complexity of your project. I am working on so large that we decided to split models.py

into multiple files in the models directory. __init__.py

models from each file are imported in this directory.



Two scoop is basically a style of how to write Django code. I recommend it.

0


source


I might recommend DjangoGirls or Djangoproject while you are bringing it up.

It took several months looking at Django to find that for a project I was included in, while it was highly recommended, it ended up getting a little overwhelmed in the end, so it took a bit of backfilling to code.

I was looking for a smaller set of codes that Flask did better, but it was an even faster prototype bundle with what I found on GitHub.

0


source







All Articles