[Answered ]-I'm getting a "AttributeError: module 'django.views' has no attribute 'my_form'" even though I have defined the function

1👍

You are importing the wrong module, you are importing it from django, so not your own. You can use:

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

from app_name.views import my_form

urlpatterns = [
    path('admin/', admin.site.urls),
    path('form', my_form, name='form'),
]

Where app_name is the name of the app where you have a views.py where you defined that view.


Note: URLs normally have a trailing slash (i.e. form/ instead of form). In fact, by default the APPEND_SLASH setting [Django-doc], which is by default set to True, will first try to match the path, and if no match is found, and the requested path has no slash, it will retry with an appended slash.

Leave a comment