私はこれでしばらくの間、私の髪を引っ張っています。私はmod_wsgiマシンでApacheサーバにテストサーバから私のdjangoアプリケーションを配備しています。 djangoユーザー認証システム以外はすべてが動作しているようですが、django_sessionテーブルにセッションを書き込んでいるようですが、何らかのバリデーションが行われます。これは、ビューの@login_required()が常にfalseを返すことです。アプリ管理ページへのアクセスが拒否されました。 私が行った研究では、パラメータの不足である可能性があります。 WSGIPassAuthorizationがapache2.confファイルでオンになっていますが、機能しませんでした。Djangoはmod_wsgiで認証していません
私のバーチャルホストのファイル:
<VirtualHost *:80>
ServerName myapp.cl
ServerAlias *.myapp.cl myapp.cl
Alias /static /home/ubuntu/django_projects/myapp/static
<Directory /home/ubuntu/django_projects/myapp/static>
Require all granted
</Directory>
<Directory /home/ubuntu/django_projects/myapp/myapp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIProcessGroup myapp
WSGIDaemonProcess myapp python-path=/home/ubuntu/django_projects/myapp
WSGIScriptAlias//home/ubuntu/django_projects/myapp/myapp/wsgi.py process-group=myapp application-group=%{GLOBAL}
</VirtualHost>
と私のurl_file:
rom django.conf.urls import url, include
from django.contrib import admin
from . import views as views_ini
from django.contrib.auth.views import login, logout, password_change, password_change_done
from myapp.views import aviso_sistema, inicio, LoginForm
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^login/$', login, {'template_name': 'loginrex.html',
'authentication_form': LoginForm,
}, name='django.contrib.auth.views.login'),
url(r'^logout/$', logout, {'next_page': '/login'}, name='logout'),
# ....Avisos del sistema
url(r'^aviso_sistema/(?P<titulo>[\w\ ]+)/(?P<detalle>[\w\ ]+)/(?P<tipo>[\w\ ]+)$', aviso_sistema, name='aviso_sistema'),
]
私/myapp/myapp/views.py
from django.shortcuts import render, redirect, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import AuthenticationForm
from django import forms
from myapp.definiciones.preferenciasDefi import unaPref
from myapp.deposito import procesoAnombre
from django.shortcuts import redirect
from django.conf import settings
@login_required()
def inicio(request):
#if not request.user.is_authenticated:
# raise ValueError('Usuario OK pero no logueado')
# return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
mdp = unaPref('mesActual')
dato = procesoAnombre(mdp)
datos = {
'mmp': dato,
'idv': ' ',
}
return render(request, 'inicio.html', datos)
class LoginForm(AuthenticationForm):
username = forms.CharField(label="Usuario", max_length=30,
widget=forms.TextInput(attrs={'class': 'form-control', 'name': 'username'}),
)
password = forms.CharField(label="Clave", max_length=30,
widget=forms.PasswordInput(attrs={'class': 'form-control', 'name': 'password'}),
)
# ........Genera los avisos del sistema
def aviso_sistema(request, titulo, detalle, tipo):
datos = {
'titulo': titulo,
'detalle': detalle,
'tipo': tipo,
}
return render(request, 'aviso_sistema.html', datos)
私は本当にこれでいくつかの助けをいただければ幸いです。 ありがとう
ユーザーが定義されていますか?どうやってそれらを作りましたか? –
スーパーユーザーを作成しました。 python manage.pyスーパーユーザーを作成 テーブルauth_user –
にWSGIPassAuthorizationを設定しました。これは、非セッションベースの認証を使用する場合に必要なものです。 – Jayground