Specific Url in Django

1

I am rewriting a website using Django. This is a blog and I need the urls to be the same as the old site so that the site does not lose ranking in the search engines. What would be the best way to handle this problem?

    
asked by anonymous 15.02.2017 / 20:23

1 answer

1

In practice, you need to create the same URL structure for the current blog in URL dispatcher of Django.

Below is an example of a URL definition (copied from Django documentation). You need to make the necessary adaptations for your new blog based on the URL structure of the current blog. The dispatcher URL uses regular expressions to define the paths:

from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^articles/2003/$', views.special_case_2003),
    url(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive),
    url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', views.month_archive),
    url(r'^articles/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', views.article_detail),
]

The first step is to identify exactly what the current URL structure is. Depending on the type / technology of the current blog, it may be in configuration files, or inside the .htaccess file. If you do not have this structure available, you can also try to find out "in the eye" by looking at the URLs that appear in the browser.

The second step is to replicate this structure in the URL dispatcher (usually in the urls.py file).

    
15.02.2017 / 20:59