Monday, August 26, 2019

Re: page not found but url exists

admin/ urls are working fine?
if you put print('hello0) at first line inside cregister, you see at the console?

If yes the problem is in redirects


Missatge de Kean <keanld1@gmail.com> del dia dl., 26 d'ag. 2019 a les 19:32:
Hi Gil,

please see

views.cregister

def cregister(request):
    next = request.GET.get('next')
    form = CUserRegisterForm(request.POST or None)
    if form.is_valid():
        user = form.save(commit=False)
        password1 = form.cleaned_data.get('password1')
        password1 = form.cleaned_data.get('password2')
        user.setpassword(password1)
        user.setpassword(password2)
        user.save()
        new_user = authenticate(username=username, password=password)
        login(request, user)
        if next:
            return redirect('next')
        return redirect('cpage')

    context = {

        'form': form,

    }
    return render(request, "cregister.html", context)

projectname/urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('core.urls')),
]

Best,

K
On 26 Aug 2019, at 18:29, Gil Obradors <gil.obradors@gmail.com> wrote:

Hi!

Can you paste views.cregister
and projectname/urls.py ?



Missatge de Kean <keanld1@gmail.com> del dia dl., 26 d'ag. 2019 a les 19:10:
Hi, 

I'm new to Django. I created several urls, in urls.py, however, when I try to navigate to the URL it says page not found.

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/register

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

  1. admin/
  2. [name='home']
  3. /login [name='clogin']
  4. /login/customer [name='cpage']
  5. /register [name='cregister']
  6. /register/customer [name='cpage']

The current path, register, didn't match any of these.






urls.py

from django.conf.urls import url
from django.urls import path
from . import views

urlpatterns = [

    path('', views.home, name='home'),
    path('/login', views.clogin, name='clogin'),
    path('/login/customer', views.cpage, name='cpage'),
    path('/register', views.cregister, name='cregister'),
    path('/register/customer', views.cpage, name='cpage'),
    path('/logout', views.clogout, name='clogout'),
    
]


Please can anyone advise, if they had this issue and how they resolved,

Best,

K

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8a72d003-fcf7-4280-8635-6f4986f3e002%40googlegroups.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK-JoTTb_a4392MBgNy12vVCayYtsxzijfC%3DznY3NK5kP5Bcfg%40mail.gmail.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/AE4A7AB2-C1BA-42DE-8C45-44D8B3133FCC%40gmail.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAK-JoTQOb7nj%3DE9fmcnmS4tONTOfB85sGAfNy0Xr_aF5q8yP3w%40mail.gmail.com.

No comments:

Post a Comment