Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This version works (so you can assume the models and templates work):
- [first_project]
- [settings.py]
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'first_app',
- 'help',
- 'users',
- ]
- [urls.py]
- from django.contrib import admin
- from django.urls import path, include
- from first_app import views
- urlpatterns = [
- path('', views.index, name="index"),
- path('first_app/', include('first_app.urls')),
- path('users/', include('users.urls')),
- path('help/', include('help.urls')),
- path('admin/', admin.site.urls),
- ]
- [first_app]
- [urls.py]
- from django.urls import path
- from . import views
- urlpatterns = [
- path('', views.index, name='index'),
- ]
- [views.py]
- from django.shortcuts import render
- from django.http import HttpResponse
- from first_app.models import Topic, Webpage, AccessRecord
- def index(request):
- webpages_list = AccessRecord.objects.order_by('date')
- date_dict = {'access_records':webpages_list}
- return render(request,'first_app/index.html',context=date_dict)
- [help]
- [urls.py]
- from django.urls import path
- from . import views
- urlpatterns = [
- path('', views.help, name='help'),
- ]
- [views.py]
- from django.shortcuts import render
- from django.http import HttpResponse
- def help(request):
- dict_vars = {'var_name':'Jules'}
- return render(request,'help/help.html',context=dict_vars)
- [users]
- [urls.py]
- from django.urls import path
- from . import views
- urlpatterns = [
- path('', views.users, name='users'),
- ]
- [views.py]
- from django.shortcuts import render
- from django.http import HttpResponse
- def users(request):
- dict_vars = {'var_name':'Jules'}
- return render(request,'users/users.html',context=dict_vars)
- This version does not work.
- - The users app is removed and view moved to first_app
- - The users.html template is moved to the correct template folder
- - the help app does not change; it is just here for completeness
- [first_project]
- [settings.py]
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'first_app',
- 'help',
- ]
- [urls.py]
- from django.contrib import admin
- from django.urls import path, include
- from first_app import views
- urlpatterns = [
- path('', views.index, name="index"),
- path('first_app/', include('first_app.urls')),
- path('users/', include('first_app.urls')), <---- this line changes
- path('help/', include('help.urls')),
- path('admin/', admin.site.urls),
- ]
- [first_app]
- [urls.py]
- from django.urls import path
- from . import views
- urlpatterns = [
- path('', views.index, name='index'),
- path('users/', views.users, name='users'),
- ]
- [views.py]
- from django.shortcuts import render
- from django.http import HttpResponse
- from first_app.models import Topic, Webpage, AccessRecord
- def index(request):
- webpages_list = AccessRecord.objects.order_by('date')
- date_dict = {'access_records':webpages_list}
- return render(request,'first_app/index.html',context=date_dict)
- def users(request):
- dict_vars = {'var_name':'Jules'}
- return render(request,'first_app/users.html',context=dict_vars)
- [help]
- [urls.py]
- from django.urls import path
- from . import views
- urlpatterns = [
- path('', views.help, name='help'),
- ]
- [views.py]
- from django.shortcuts import render
- from django.http import HttpResponse
- def help(request):
- dict_vars = {'var_name':'Jules'}
- return render(request,'help/help.html',context=dict_vars)
- In the first version, when I navigate to http://127.0.0.1:8000/users I see users.html, as expected.
- In the second version, when I navigate to http://127.0.0.1:8000/users I see index.html from first_app!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement