Joe
Joe

Reputation: 31

Adding new apps to django

I have followed the guidelines for starting up learning django, but i have a question. if I want to add a new app onto the polls app they instructed, called poll2, can I just copy + paste the polls folder? (this is for example if I want to make an identical app, with same functionality). Is there anything else special i need to do, other than make admin.py load poll2 along with polls?

Upvotes: 2

Views: 504

Answers (2)

bakkal
bakkal

Reputation: 55448

There is a reason people say "copy paste is evil"

However if you're willing to, you just need to make sure to change references (if they exist) to poll inside your new app to poll2.

Because e.g. in poll/somefile.py there may be an absolute import in this form:

from poll import someting

Which isn't going to do well if that gets copied into poll2 app and the goal is to use poll2 and not use poll from poll2

And the list of things to rename from poll to poll2 goes on and on. E.g. templates in poll/templates/poll/something.html, and perhaps URL namespaces, etc

Bottom line, doable, just make sure absolute references are renamed to poll2

Upvotes: 3

Alex Morozov
Alex Morozov

Reputation: 5993

Nothing. As long as your apps live in the different folders, they are completely independent apps for Django. Just make sure they both are loaded in your settings.INSTALLED_APPS.

* Catch #1: If you have the identical template tags files, rename them so they would become polls_tags.py and polls2_tags.py.

* Catch #2: Don't forget to rename your templates so that templates/polls/index.html' becomes 'templates/polls2/index.html.

Upvotes: 0

Related Questions