所以我试图从我的模型中渲染数据,user_profile并且出于某种原因,当我尝试将create_view_two视图渲染到我的项目根目录时home.html,页面不会渲染视图。
但是,如果我的create_view_two视图指向不同的页面,它就可以工作。
下面的例子:
user_profile/urls.py
urlpatterns = [
path("test/", create_view_two, name='home'),
]
user_profile/views.py
return render(request, "test.html", context)
我想将这个观点指向我的项目的根源,这localhost:8000不是什么不同的东西。我怎样才能做到这一点?
任何帮助都非常感谢。
干杯
user_profile/views.py
from django.http import HttpResponse, HttpResponseRedirect
from django.http import HttpResponseNotFound
from django.shortcuts import get_object_or_404
from django.shortcuts import render, redirect
from django.conf import settings
from .forms import HomeForm
from .models import Listing
from users.models import CustomUser
def create_view_two(request):
form = HomeForm(request.POST or None, request.FILES or None,)
user_profile = Listing.objects.all()
user = request.user
context = {
'form': form, 'user_profile': user_profile
}
return render(request, "home.html", context)
user_profile/urls.py
from django.conf.urls import url
from . import views
from django.urls import path, include
from django.conf import settings
from .views import create_view, create_view_two
urlpatterns = [
path('myaccount/', create_view, name='myaccount'),
path('', create_view_two, name='home'),
]
master_application/urls.py
from django.conf.urls import url
from django.contrib import admin
from django.urls import path
from django.urls import path, include
from django.views.generic.base import TemplateView
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('', TemplateView.as_view(template_name='home.html'), name='home'),
path('admin/', admin.site.urls),
path('', include('user_profile.urls')),
path('', include('users.urls')),
path('', include('django.contrib.auth.urls')),
path('users/', include('users.urls')),
path('users/', include('django.contrib.auth.urls')),
path('', include('myapp.urls')),
]
慕桂英3389331
相关分类