2

这是我的应用程序models.py文件auth:[在中创建auth_articlesql]

from django.db import models
class Article(models.Model):
    title=models.TextField()
    content=models.TextField()

但是,我无法在登录时检索auth_article字段。sql我正在使用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)
...
...
4

1 回答 1

4

查看 render_to_response 文档https://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to-response

它应该是这样的:

return render_to_response('home.html', {'articles': aa}, RequestContext(request))
于 2012-12-25T08:08:14.347 回答