Page Redirect Error -URL

Asked

Viewed 539 times

1

I’m super beginner with Python and Django and unfortunately I’m suffering a lot with urls. The problem is that "Página não encontrada (404)". Below are excerpts of the code:

py.

from django.conf.urls import patterns, include, url
import web.views
urlpatterns = [

    #url(r'^$/', 'web.views.home', name='home'),
    url(r'^web/', 'views.index'),

]

py views.

from django.shortcuts import render_to_response, render
from django.http import HttpResponseRedirect # Funcao para redirecionar o usuario
#Criar as Views aqui

# pagina inicial do projeto dweb
def index(request):
    return render_to_response("index.html")
  • You are using DEBUG = True in the settings.py? What URL is this error giving? If your server is running for example on localhost:8000 (the pattern of runserver) then the only page that should be available - by the rules of your urls.py - is the http://localhost:8000/web/. Is this URL giving 404? Or is it another?

  • Hello Earendul, Good Morning!!... Yes, I am using DEBUG = True. This is the url q is giving error: url(r' web/', 'views.index'), even if I add this url. It redirects me to this: http://127.0.0.1:8000/. Then there’s the mistake!!

  • That one views.index shouldn’t be web.views.index?

  • Hello mgibsonbr, good afternoon!!... I managed to solve more in another way, see what I posted now! But this question you asked me is very correct, it would be just in the previous case!!... Thank you :)!!

1 answer

1

doing some research I managed to solve this problem in another way. But I thank you for your help! See below how it was:

py.

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

urlpatterns = [

    url(r'^admin/',include(admin.site.urls)),
    url(r'^$', 'web.views.homepage', name="index"),

]

py views.

__author__ = 'Sara Fernandes'

from django.shortcuts import render_to_response, render
from django.template import RequestContext, loader

#from django.http import HttpResponseRedirect # Funcao para redirecionar o usuario
#Criar as Views aqui

# pagina inicial do projeto dweb

def homepage(request):
    return render_to_response('index.html',
        context_instance= RequestContext(request))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.