简体   繁体   中英

Django define default view with IP address

I migrated my Django project to an Ubuntu distant server . I'm using mod_wsgi in order to runserver and I have some questions about default page.

I'm really new in this domain and I apologize if my question is bad or useless ..

When I want to connect to my Django application, I have to write something like that :

http://172.XX.XX.XXX/Home/login/

If I write just :

http://172.XX.XX.XXX

I get :

Page not found

Using the URLconf defined in Etat_civil.urls, Django tried these URL patterns, in this order:

    ^admin/
    ^BirthCertificate/
    ^Identity/
    ^Accueil/
    ^Home/
    ^captcha/
    ^Mairie/

The current URL, , didn't match any of these.

My question is :

How I can define redirected url in order to write http://172.XX.XX.XXX in my browser and go directly to http://172.XX.XX.XXX/Home/login/ for example ?

This is urls.py file from my project :

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

from BirthCertificate import views
from Identity import views
from Accueil import views
from log import views
from Mairie import views


urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^BirthCertificate/', include('BirthCertificate.urls')),
    url(r'^Identity/', include('Identity.urls')),
    url(r'^Accueil/', include('Accueil.urls')),
    url(r'^Home/', include('log.urls')),
    url(r'^captcha/', include('captcha.urls')),
    url(r'^Mairie/', include('Mairie.urls')), 
] 

Because I just want for example, write my IP adress in order to access to my Django application and not write all the time a complete url.

If you need some files (apache2 files, ...) please tell me which one I have to post there.

Include this in views.py file of your any app:

from django.shortcuts import redirect

def some_view(request):
    return redirect('/Home/login/')

Suppose the view is in log app then, Include this in your urls.py:

from log.views import some_view

urlpatterns = [
    url(r'^$', some_view,name='index'),
    url(r'^admin/', admin.site.urls),
    url(r'^BirthCertificate/', include('BirthCertificate.urls')),
    url(r'^Identity/', include('Identity.urls')),
    url(r'^Accueil/', include('Accueil.urls')),
    url(r'^Home/', include('log.urls')),
    url(r'^captcha/', include('captcha.urls')),
    url(r'^Mairie/', include('Mairie.urls')), 
] 

One method is to use RedirectView by making the following changes to your urls.py :

from django.views.generic.base import RedirectView

urlpatterns = [
    url(r'^$', RedirectView.as_view(url='/Home'), name='home'),
    ...
]

You can either do this in Django or Configure from your webserver. Django has redirects app go through https://docs.djangoproject.com/en/1.10/ref/contrib/redirects/ for more info. You just add the source and redirect urls in the redirects section of your django admin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM