skip to Main Content

Here is my base.html

      <div class="container">
    <div class="center">

         <form action='simple_test'> 
      <button id="simple_test" class="button-3d">  Generate</button>
         </form>
   </div>
     </div>

Here is my view.py

from django.http import HttpResponse 
from django.shortcuts import render
from datetime import datetime
from django.template import loader
from django.core.files import File
from .unun import some_func
import random
import os

def index(request):
    strinput = {}
    glued, oldgued = some_func()
    strinput['IntPassHMTL'] = 433
    strinput['StrPassHMTL'] = glued
    strinput['BeforeGlued'] = oldgued

    return render(request,'index.html', strinput )


def simple_test(request):
    strinput = {}
    # glued, oldgued = some_func()
    strinput['IntPassHMTL'] = 433
    strinput['StrPassHMTL'] = "glued"
    strinput['BeforeGlued'] = "oldgued"
    print("Words?")
    return HttpResponse("This is a fake 404!")

Here is my urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    print("simple_test", views.simple_test),
    path('', views.index, name="index"),

]

misspelled pointed by @0svoid

    path("simple_test", views.simple_test),
    #print("simple_test", views.simple_test),

I tried to apply this solution to my codes and they still do not work right for my project. Not sure what I am missing.

enter image description here

2

Answers


  1. Try adding / after your URL and in second URL you have print instead of path make these changes it should work.

    ”’

        urlpatterns = [
            path('admin/', admin.site.urls),
            path("simple_test/", views.simple_test),
            path('', views.index, name="index"),
        ]
    

    ”’

    Login or Signup to reply.
  2. Instead of path you have put print, so you haven’t actually added the URL to your urlpatterns list! Try this:

        urlpatterns = [
            path('admin/', admin.site.urls),
            path("simple_test/", views.simple_test),
            path('', views.index, name="index"),
        ]
    

    The forward slash is only mandatory if you set APPEND_SLASH = True in your settings.py file.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search