2
這是我models.py
文件我auth
應用程序:這sql
創建auth_article
表]檢索Django的登錄定製SQL條目
from django.db import models
class Article(models.Model):
title=models.TextField()
content=models.TextField()
不過,我無法在登錄從sql
檢索auth_article
領域。 我正在使用User
模型進行登錄。
from django.shortcuts import render_to_response
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
from auth.models import Article
def login_user(request):
state = "Please login below..."
username = password = ''
if request.POST:
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
state = "You're successfully logged in!"
user_info = dict(username=username, email=user.email, fullname=user.get_full_name(), id=user.id)
aa=Article.objects.all()
return render_to_response('home.html', aa)
...
...
我不能從文檔理解。我嘗試了一些東西,但只是搞砸了。可以請告訴我如何將'auth_article'的'sql'條目傳遞給我的'home.html'? – xan
在我的代碼中就像詞典'{'articles':aa}'一樣。然後,您可以在模板「{%文章中的文章%}中使用它......' – sneawo
謝謝了。我浪費了將近2天的時間。 但我還有一個疑問。我試圖用'creator'獲得'Article'對象,它等於上面'user_info'中的'id' [來自'user_info']。 但是, 'aa = Article.objects.get(creator = id)'不起作用。 – xan