1. 程式人生 > >Django處理靜態html檔案

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',
)