我已经开发了用于在我的 django 应用程序中查看组列表的模板。我开始知道的是,在更多组之后,页面正在向下滚动。我无法看到所有组的名称。而且我只想在开始时查看 4 个组名称,然后在单击加载更多按钮后,必须显示接下来的 4 个组。我无法做到这一点。
{% extends "groups/group_base.html" %}
{% block pregroup %}
<div class="col-md-4">
<div class="content">
{% if user.is_authenticated %}
<h2>
Welcome back
<a href="{% url 'posts:for_user' username=user.username %}">@{{user.username }}</a>
</h2>
{% endif %}
<h2>Groups</h2>
<p>Welcome to the Groups Page! Select a Group with a shared interest!</p>
</div>
{% if user.is_authenticated %}
<a href="{% url 'groups:create' %}" class="btn btn-md btn-fill btn-warning"><span class="glyphicon glyphicon-plus-sign"></span> Create New Group!</a>
{% endif %}
</div>
{% endblock %}
{% block group_content %} …Run Code Online (Sandbox Code Playgroud) 我创建了一个小型 django 项目。当我尝试重定向到特定页面时,网址不会更改,但所需的页面已正确加载。我正在使用 render() 重定向到特定页面。
视图.py 文件:
def create_album(request):
if not request.user.is_authenticated():
return render(request, 'photo/login.html')
else:
form = AlbumForm(request.POST or None, request.FILES or None)
if form.is_valid():
album = form.save(commit=False)
album.user = request.user
album.album_logo = request.FILES['album_logo']
album.save()
return render(request, 'photo/detail.html', {'album': album})
context = {
"form": form,
}
return render(request, 'photo/create_album.html', context)
def register(request):
form = UserForm(request.POST or None)
if form.is_valid():
user = form.save(commit=False)
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user.set_password(password)
user.save()
user = authenticate(username=username, password=password)
if user is not None: …Run Code Online (Sandbox Code Playgroud)