pintee
pintee

Reputation: 119

Page Not Found Error occured while trying to render form in django

I've been following the instructions here.

This is the error it gives me, when i try to run it on localhost:

Page not found (404)
Request Method:     GET
Request URL:    http://localhost:7000/account.html

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

[name='index']
[name='account']
db/ [name='db']
admin/
^celery-progress/

The current path, account.html, 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.

This is what i have in my urls.py

 urlpatterns = [
 path("", hello.views.index, name="index"),
 path("", hello.views.account, name="account"),
 path("db/", hello.views.db, name="db"),
 path("admin/", admin.site.urls),
 re_path(r'^celery-progress/', include('celery_progress.urls'))
 ]

This is what i have in views.py

def account(request):
if request.method == 'POST':
    form = AccountForm(request.POST)

    if form.is_valid():
        return HttpResponseRedirect('loading.html')

else:
    form = Nameform()

return render(request, 'account.html', {'form': form})

Finally this is the form itself(account.html):

<form action="/account/" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>

I have the feeling i'm missing something really simple but i can't for the life of me see it. Any help would be greatly appreciated.

Upvotes: 0

Views: 122

Answers (2)

Onilol
Onilol

Reputation: 1339

You are requesting for the url that could match the string /account/ but in your urlpatterns variable you have an empty string so it can't match anything.

Remember that the first argument of urlpatterns is a pattern string that can be matched with regex.

Perhaps you could map it like:

path("/account/", hello.views.account, name="account")

Upvotes: 0

JPG
JPG

Reputation: 88499

First, you need to change the URL patterns, because multiple views (hello.views.index and hello.views.account) are pointing towards the same pattern

urlpatterns = [
    path("index/", hello.views.index, name="index"),
    path("account/", hello.views.account, name="account"),
    path("db/", hello.views.db, name="db"),
    path("admin/", admin.site.urls),
    re_path(r'^celery-progress/', include('celery_progress.urls'))
]

then, access the URL, http://localhost:7000/account/

Upvotes: 3

Related Questions