0
請問我的英文不是最好的。Django課堂問題
我對django和python很陌生,我嘗試編程用戶認證。 我用Django文檔,一切工作正常用下面這些代碼:
def anges(request):
username = []
password = []
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
render_to_response ('registration/login.html', {'username': username, 'password': password})
if user is not None:
if user.is_active:
login(request, user)
angestellte_list = Employee.objects.all().order_by('lastname')
return render_to_response(("emp/angestellte.html"), {'angestellte_list': angestellte_list})
else:
return HttpResponse('disabled account')
else:
return HttpResponse('invalid login')
else:
return render_to_response ('registration/login.html', {'username':username, 'password':password})
但是,這僅僅是一個功能,我想使用面向我在我的views.py等功能此對象,因爲乾的。 這只是第一個測試,但它不工作,因爲調試器說:「全球名‘請求’沒有定義」 這是我的代碼:
class einloggen:
def __init__(self):
self.Username = request.POST['username']
def angestellte(self):
return HttpResponse("hello")
我如何使用請求變量的類或還有什麼需要考慮的嗎?
Django已經有一個完整的用戶認證應用程序。爲什麼寫自己的? – 2011-05-25 12:05:54
...或者換句話說,你需要什麼'django.contrib.auth'缺乏? – 2011-05-25 12:16:02