Tuesday, January 31, 2017

Re: How can I solve the broken home page in the root folder?

Thank you very much.

I added the following to main site urls.py:

url(r'^$', views.home, name='home'),

and added the following to the /data/views.py file.

def home(request):
return HttpResponse("<h1>Main Page</h1>")

This somewhat makes sense, just wondering why the main site does not require a views.py file


On Tuesday, January 31, 2017 at 1:57:53 PM UTC, ludovic coues wrote:
Try "url(r'^/', include('data.urls'))," in url_patterns. This should do what you want.

Alternatively, you can set a simple view on r'^$' that will redirect to your main app.


On 31 Jan 2017 1:09 p.m., "Thames Khi" <tham...@gmail.com> wrote:
I followed a simple tutorial to create a sample application in DJango. Here is my code for urls.py in the root folder:

from django.conf.urls import url, include
from django.contrib import admin
#from data import views

urlpatterns = [
    
url(r'^data/', include('data.urls')),
url(r'^admin/', admin.site.urls),


I get this error:

Page not found (404)

Request Method:GET
Request URL:http://<my IP>/

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

  1. ^data/
  2. ^admin/

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

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page. 



The app http://<my IP>/data/ works fine.


If I remove the line: url(r'^data/', include('data.urls')),


then the root app works a treat:


It worked!

Congratulations on your first Django-powered page.


Is there a way to solve this or is there a way to redirect the page to another app? I really do not want to give out a website address with <my url>/data

Thank you very much.

Khi


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/05cf9421-5481-4e6a-b1a9-0ae874dbe860%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e37f2c55-1b97-4d70-8a9a-5e9d32c9b54b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment