Q:

Redirecting to the required page but url is not changing in django

I have created a small django project. In that when i try to redirect to a specific page, the url is not changing but the required page is getting loaded properly. I am using render() to redirect to the specific pages. 
views.py file:
    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:
            if user.is_active:
                login(request, user)
                albums = Album.objects.filter(user=request.user)
                return render(request, 'photo/index.html', {'albums': albums})
    context = {
        "form": form,
    }
    return render(request, 'photo/register.html', context)
    def detail(request, album_id):
        if not request.user.is_authenticated():
            return render(request, 'photo/login.html')
        else:
            user = request.user
            album = get_object_or_404(Album, pk=album_id)
            return render(request, 'photo/detail.html', {'album': album, 'user': user})

urls.py file:
    from django.conf.urls import url
from . import views

app_name = 'photo'

urlpatterns = [
    url(r'^login_user/$', views.login_user, name='login_user'),
    url(r'^register/$', views.register, name='register'),
    url(r'^logout_user/$', views.logout_user, name='logout_user'),
    url(r'^(?P<album_id>[0-9]+)/$', views.detail, name='detail'),
    url(r'^create_album/$', views.create_album, name='create_album'),
    url(r'^(?P<album_id>[0-9]+)/create_picture/$', views.create_picture, name='create_picture'),
    url(r'^(?P<album_id>[0-9]+)/delete_album/$', views.delete_album, name='delete_album'),
    url(r'^(?P<song_id>[0-9]+)/favorite/$', views.favorite, name='favorite'),
    url(r'^(?P<album_id>[0-9]+)/favorite_album/$', views.favorite_album, name='favorite_album'),
    url(r'^(?P<album_id>[0-9]+)/delete_pic/(?P<song_id>[0-9]+)/$', views.delete_pic, name='delete_pic'),
    url(r'^$', views.index, name='index'),
    ]

The problem is when i try to create an album, i get the url as:127.0.0.1:8000/create_album/
After creating the album, the page has to redirected to detail.html page. The url for that should be:127.0.0.1:8000/10/ (10 is the album_id)
But the url is not changing.Please help me.

A:

You misunderstood render. render, as its name, just renders the html page. Even if you render the detail.html page, the request context here is still the create_album request.
What you'd need here is redirect (https://docs.djangoproject.com/en/2.0/topics/http/shortcuts/#redirect):
def create_album(request):
    if not request.user.is_authenticated():
        return redirect('photo:login_user')
    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 redirect('photo:detail', album_id=album.id)

        context = {
            "form": form,
        }
        return render(request, 'photo/create_album.html', context)

