-2
我正在創建用戶創建並且贊成的所有帖子的摘要頁面。但是,它試圖檢索用戶上傳的帖子時拋出上面的錯誤,我不知道爲什麼?name'user'沒有被定義django
模式
class Aircraft(AircraftModelBase):
user = models.ForeignKey(User)
manufacturer = SortableForeignKey(Manufacturer)
aircraft_type = SortableForeignKey(AircraftType)
body = SortableForeignKey(Body)
engines = models.PositiveSmallIntegerField(default=1)
查看
def account_overview(request):
fav_aircraft = FavoritedAircraft.objects.filter(user__id=request.user.id)
uploaded_aircraft = Aircraft.objects.filter(user=user) <---- HERE!!!!
fav_airline = FavoritedAirline.objects.filter(user__id=request.user.id)
return render(request, 'account/account_overview.html', {'favAircraft':fav_aircraft,
'favAirline':fav_airline,
'UploadedAircraft':uploaded_aircraft})
模板
{% if UploadedAircraft %}
<div class="col-md-12">
<i><h1><strong>Your Aircraft Uploads..</strong></h1></i>
{% for aircraft in UploadedAircraft %}
<div class="col-lg-offset-0 col-md-4 col-sm-3 item">
<div class="box"><img src="{{ aircraft.aircraft.image.url }}" width="200px" height="200px" alt="{{ aircraft.aircraft.title }}"/></a>
<h3 class="name">{{ aircraft.aircraft.name }}</h3>
<h4><em>Range: {{ aircraft.aircraft.maximum_range }}</em></h4>
<a href="{% url 'aircraft_update' %}"><button class="btn btn-default" type="button">Edit </button></a>
<button class="btn btn-default" type="button">Delete </button>
</div>
{% endfor %}
</div>
</div>
{% else %}
<h2 class="text-center">Opps.. You don't seem to have any uploads..</h2></div>
{% endif %}
而不是'user = user',你想'user = request.user'。 – castis