Поэтому я пытаюсь отобразить данные из моей модели с именем 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')),
]
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
MyApp / urls.py
from django.urls import path, include
from django.conf.urls import url
from django.conf import settings
from . import views
from .views import HomePageView, MyAccountView, AboutPageView, PrivacyPageView, ContactPageView
urlpatterns = [
path('', HomePageView.as_view(), name='home'),
path('about/', AboutPageView.as_view(), name='about'),
path('privacy/', PrivacyPageView.as_view(), name='privacy'),
path('contact/', ContactPageView.as_view(), name='contact'),
path('myaccount/', MyAccountView.as_view(), name='myaccount'),
]
home.html
{% for profile_two in user_profile%}
<p>{{ profile_two.rank }}</p>
{% endfor %}