Monday, 15 September 2014

django urls.py structure for login, logout, signup ( not app-specific urls ) : in users app or project default app? -


question

I'm managing a small project project. And our team has a disputed view about this problem:

Which entry, logout, signup (not an app-specific router) has been suggested?

logout url (r '^ login / $', 'users.views.login_view', name = 'login'), url (r '^ logout / $ ',' Users.views.logout_view ', name =' logout '), url (r' ^ signup / $ ',' users.views.signup ', name =' signup '),

1 MY_PROJECT > urls.py

Reason: Total in MY_PROJECT / urls.py URL should be viewed and login, logout, signup is not an app-specific url.

2. Users > urls.py

Reason: Login, logout, sign up on the user app, because the view is implemented in User / Approach \ , and this is the preferred method in terms of modularity

folder structure

  ├── MY_PROJECT │ ├── __init__.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── Management └── User ├── __init__.py ├─ ─ models .py ├── urls.py └── views.py  

Additional information for inequality

User app to expand the base user using UserProfile

From the Django.contrib.auth.models import model to django.db
  import user class UserProfile (models.Model): user = models.OneToOneField (user, exclusive = true, primary_key = true) And so on ...  

And also, the default login, log Out, expand the signup view. Def logout_view (request): Logout (request) Redirect redirect ("Home")

If you put all the normal URL of your project in MY_PROJECT / urls.py, the smaller lines of this file are too much, then when you need to track a specific URL, then seeing this file can be difficult.

So if all URLs in MY_PROJECT / urls.py are in the following format, you can save a lot of time in searching for it. A specific URL and your code is even more cleaner.

But if your user ( If the app is large, it may be a better way if you use a different urls.py for login / logout / signup, that means your users The app is kept separate from urls.py and auth_urls.py .


No comments:

Post a Comment