Django处理静态html文件

from django.views.generic import TemplateView

urlpatterns = [
    url(r'^xadmin/', xadmin.site.urls),
    url(r'^$', TemplateView.as_view(template_name='index.html'), name='index')
]

自定义后台认证方法

首先在users的views.py中定义如下类

from django.contrib.auth.backends import ModelBackend
from django.db.models import Q


class CustomBackend(ModelBackend):
    def authenticate(self, username=None, password=None, **kwargs):
        try:
            user = UserProfile.objects.get(Q(username=username)|Q(email=username))
            if user.check_password(password):
                return user
        except Exception as e:
            return None

然后在settings.py中配置

AUTHENTICATION——BACKENDS = (
    'users.views.CustomBackend',
)

你可能感兴趣的:(Django)