所以,我有一个网站,用户在导航栏上单击“我的博客”,它会向下滚动到 index.html 的那个部分(例如 8000/#blog-section)。我已经在索引页面上有了联系表格。现在我正在尝试创建博客逻辑以呈现三篇博客文章,但它显示为空白?
我可以为同一个“index.html”页面创建一个单独的视图吗?
Views.py
def index_view(request):
posts = Post.objects.all().order_by('-created_on')
context ={
'posts': posts,
'name': name,
}
form = ContactForm()
if request.method == 'POST':
form = ContactForm(data=request.POST)
if form.is_valid():
# Send email goes here
name = request.POST.get('name')
subject = request.POST.get('subject')
email = request.POST.get('email')
message = request.POST.get('message')
template = get_template('contact_form.txt')
context = {
'subject': subject,
'email' : email,
'message' : message
}
content = template.render(context)
email = EmailMessage(
"Message from Portfolio",
content,
"New inquiry | Portfolio" + '',
['myemail@gmail.com'],
headers = {'Reply to': email}
)
email.send()
return HttpResponseRedirect("/")
return render(request, 'index.html', {'form': form}, context)
网址.py /博客
from django.urls import path
from . import views
urlpatterns = [
path("", views.blog_index, name="blog_index"),
path("<int:pk>/", views.blog_detail, name="blog_detail"),
path("<category>/", views.blog_category, name="blog_category"),
]
Urls.py / 投资组合
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
from django.urls import path, include
from .views import index_view, post_view
urlpatterns = [
path('admin/', admin.site.urls),
path('tinymce/', include('tinymce.urls')),
path('', index_view),
path('post/', post_view),
path("#blog-section/", include("blog.urls")),
]
慕沐林林
相关分类