My first Python web application

I am trying to write a program by running Django using the manage.py runningerver ip: port file in my Linux box as a non-root user. My first goal is that if the user enters the URL in the browser http: // ip: port , he should display something or welcome content.

So, I changed my mysite / url.py like this:

urlpatterns = patterns('', ('', ''), (r'^admin/', include(admin.site.urls)), ) 

python manage.py runningerver: starts and starts normally, but in the browser I get the following exception:

Exception type: Incorrect Configured Exceptional value: empty name for the URL pattern view is not allowed (for the pattern '')

So, how can you build a url like this:

 www.google.com www.mail.yahoo.com www.mysite.com 

Thanks in advance

+4
source share
2 answers

An empty template will match anything, so you must bind it to an empty empty string. The parameter of the second tuple must also be the name of the view.

In your URLconf:

 urlpatterns = patterns('', (r'^$', 'views.home'), # ^$ means, beginning of string followed by end of string, in other words match on exactly empty string and nothing else (r'^admin/', include(admin.site.urls)), ) 

In views.py in the same directory:

 from django.http import HttpResponse def home(request): return HttpResponse('Hello World') 
+4
source

If you are not ready to start configuring, starting and hosting your own Apache server (or another server) and register a domain name, you CANNOT change the domain name from Python / Django.

Django processes everything that comes after the domain name, for example /home/ part of the URL http://www.mysite.com/home/ .

If you are up to it, the Django book has pretty good about deploying Django and setting up the server to run it, but it does not cover all the databases.

+3
source

Source: https://habr.com/ru/post/1399078/


All Articles