def test_post_new_note(self): '''A new note exists after the user submits the form.''' # simulate data the user types into the form form_data = { 'title': 'Frogs', 'content': 'What makes a frog tongue so strong?', } # simulate the user clicking 'Submit' on the form post_request = self.factory.post('notes:create_note_form', form_data) post_request.user = self.user response = NoteCreate.as_view()(post_request) # test the view redirects to the details page self.assertEqual(response.status_code, 302) # test that the database contains the new Page note = Note.objects.last() self.assertEqual(note.title, 'Frogs') self.assertEqual(note.slug, 'frogs')
"""main_config URL Configuration The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/2.2/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.urls import path, include from notes.views import NoteCreate, NoteListView, NoteDetailView, NoteUpdate, NoteDelete urlpatterns = [ path('create', NoteCreate.as_view(), name='note-create'), path('', NoteListView.as_view(), name='note-list'), path('<int:pk>/', NoteDetailView.as_view(), name='note-detail'), path('update/<int:pk>/', NoteUpdate.as_view(), name='note-update'), path('delete/<int:pk>/', NoteDelete.as_view(), name='note-delete'), ]
from django.contrib import admin from django.urls import path from notes.views import Notes, NoteCreate, NoteDelete, NoteList, NoteUpdate urlpatterns = [ # User Admin path('admin/', admin.site.urls), # Add View path('add', NoteCreate.as_view(), name='note-add'), # Edit View path('<int:pk>/', NoteUpdate.as_view(), name='note-update'), # Delete View path('<int:pk>/delete/', NoteDelete.as_view(), name='note-delete'), # List View path('', NoteList.as_view(), name='note-list'), ]
from django.contrib.auth import views as auth_views # CHANGEME: Must include the view class. from notes.views import NoteCreate urlpatterns = patterns( '', # Examples: # url(r'^$', 'bulletin.views.home', name='home'), # url(r'^bulletin/', include('bulletin.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), url(r'^register/$', SimpleAuthRegistrationView.as_view(), name='registration_register'), url(r'^login/$', auth_views.login, {'template_name': 'registration/login.html'}, name='auth_login'), url(r'^logout/$', auth_views.logout, {'template_name': 'registration/logout.html'}, name='auth_logout'), url(r'^$', 'notes.views.index', name='home'), # CHANGEME: allow logged in users to add notes. url(r'^add/$', NoteCreate.as_view(), name='add_note'), )
from django.urls import path from notes.views import (NoteList, NoteDetail, NoteCreate, NoteUpdate, NoteDelete, post_on_medium) from django.conf import settings from django.conf.urls.static import static app_name = 'notes' urlpatterns = ([ path('', NoteCreate.as_view(), name="create_note_form"), path('home/', NoteList.as_view(), name='index'), path('<slug:slug>/edit/', NoteUpdate.as_view(), name="edit_note_form"), path('<slug:slug>/delete/', NoteDelete.as_view(), name='delete_note'), path('<slug:slug>/', NoteDetail.as_view(), name='notes-detail-page'), path(('https://medium.com/m/oauth/authorize?' + 'client_id={{clientId}}' + '&scope=basicProfile,publishPost&state={{state}}' + '&response_type=code&redirect_uri={{redirectUri}}'), post_on_medium, name='post-to-medium'), ])
from django.urls import path from notes.views import NoteCreate, NotesList, NotePage, NoteEdit, NoteDelete urlpatterns = [ path('create/', NoteCreate.as_view(), name='create note'), path('create/<int:pk>/', NoteCreate.as_view(), name='create note for lesson'), path('all/', NotesList.as_view(), name='my notes'), path('<int:pk>/', NotePage.as_view(), name='current note'), path('edit/<int:pk>/', NoteEdit.as_view(), name='edit note'), path('delete/<int:pk>/', NoteDelete.as_view(), name='delete note'), ]
from django.conf.urls import url from notes.views import NoteListView, NoteDetailView, NoteCreate, NoteUpdate, NoteDelete urlpatterns = [ url(r'^$', NoteListView.as_view(), name='note-list'), url(r'^(?P<pk>\d+)/$', NoteDetailView.as_view(), name='note-detail'), url(r'note/add/$', NoteCreate.as_view(), name='note-add'), url(r'note/(?P<pk>[0-9]+)/$', NoteUpdate.as_view(), name='note-update'), url(r'note/(?P<pk>[0-9]+)/delete/$', NoteDelete.as_view(), name='note-delete'), ]
from django.urls import re_path, path from notes.views import NoteDetailView, NoteListView, NoteCreate, NoteUpdate, NoteDelete, Dashboard, Register, \ TopicListView, TopicDetailView, TopicCreate, TopicUpdate, TopicDelete urlpatterns = [ #re_path(r'', Dashboard, name='dashboard'), re_path(r'^$', NoteListView.as_view(), name='note-list'), re_path(r'^(?P<pk>\d+)/$', NoteDetailView.as_view(), name='note-detail'), re_path(r'note/add/$', NoteCreate.as_view(), name='note-form'), re_path(r'note/(?P<pk>[0-9]+)/$', NoteUpdate.as_view(), name='note-update-form'), re_path(r'note/(?P<pk>[0-9]+)/delete/$', NoteDelete.as_view(), name='note-confirm-delete'), re_path(r'users/dashboard/', Dashboard, name='dashboard'), re_path(r'^register/', Register, name='register'), re_path(r'^topics/$', TopicListView.as_view(), name='topic-list'), re_path(r'^topics/(?P<pk>\d+)/$', TopicDetailView.as_view(), name='topic-detail'), re_path(r'topics/add/$', TopicCreate.as_view(), name='topic-form'), re_path(r'topics/(?P<pk>[0-9]+)/$', TopicUpdate.as_view(), name='topic-update-form'), re_path(r'topics/(?P<pk>[0-9]+)/delete/$', TopicDelete.as_view(), name='topic-confirm-delete'), ]
# Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() from simpleauth.views import SimpleAuthRegistrationView from django.contrib.auth import views as auth_views # CHANGEME: Must include the view class. from notes.views import NoteCreate urlpatterns = patterns('', # Examples: # url(r'^$', 'bulletin.views.home', name='home'), # url(r'^bulletin/', include('bulletin.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls)), url(r'^register/$', SimpleAuthRegistrationView.as_view(), name='registration_register'), url(r'^login/$', auth_views.login, {'template_name': 'registration/login.html'}, name='auth_login'), url(r'^logout/$', auth_views.logout, {'template_name': 'registration/logout.html'}, name='auth_logout'), url(r'^$', 'notes.views.index', name='home'), # CHANGEME: allow logged in users to add notes. url(r'^add/$', NoteCreate.as_view(), name='add_note'), )