T
T
temporary hacker hacker2018-04-16 13:49:27
Django
temporary hacker hacker, 2018-04-16 13:49:27

Link to another page, how to make 2 links different pages?

Good afternoon!
There are 2 html pages and url links

from django.contrib import admin
from django.conf.urls import url, include

urlpatterns = [
    url('admin/', admin.site.urls),
    url(r'^$', include('mainapp.urls')),
    url(r'^стейк-лосося/', include('mainapp.urls')),


]

from django.shortcuts import render

def index(request):

    context = {"name":"Django", "version":2.0}
    return render(request, 'mainapp/index.html', context)

def index_wrapper(request):
    
    context = {"name":"Django", "version":2.0}
    return render(request, 'mainapp/wrapper.html', context)

from django.conf.urls import url, include

from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^mainapp/', views.index_wrapper, name='index_wrapper'),
]

It is necessary that the link /salmon steak/ leads to wrapper.html, index.html leads to the main page, now all links lead to the same html file, you need to make sure that each html file has its own url

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-04-16
@syschel

Why do you include the same link file in two places (addresses)?

urlpatterns = [
    url(r'^$', include('mainapp.urls')),
    url(r'^стейк-лосося/', include('mainapp.urls')),
]

Nobody in the base urls.py forbids you to do this:
from django.conf.urls import url
from mainapp.views import index, index_wrapper

urlpatterns = [
    url(r'^$', index, name='index'),
    url(r'^стейк-лосося/', index_wrapper, name='index_wrapper'),
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question