每当我尝试打开我的博客文章时,我都会收到此消息。 我的博客网址为http://leonkong.com/,发布网址为http://leonkong.com/1/
错误讯息:
df1 <- structure(list(Station.ID = c(323L, 323L, 323L, 452L, 452L, 452L
), Year = c(1995L, 1996L, 1997L, 1995L, 1996L, 1997L), Jan = c(31.3,
28, 20.2, 16.2, 14.3, 20.1), Feb = c(25.2, 20.2, 22.1, 20.1,
23.1, 22.1), Mar = c(19, 17.5, 31.2, 31.2, 34.2, 32.2), Apr = c(15,
14, 12.2, 12.2, 14.2, 13.2), May = c(12, 10.5, 12.5, 12.5, 13.5,
11.5), Jun = c(10.1, 12.2, 22.1, 22.1, 19.1, 18.1)), .Names = c("Station.ID",
"Year", "Jan", "Feb", "Mar", "Apr", "May", "Jun"), class = "data.frame", row.names = c(NA,
-6L))
我使用Django 2.0.4版,最近使用AWS RDS创建了MySQL。
仅供参考,like_action功能代码(views.py):
NoReverseMatch at /1/
Reverse for 'like_action' with keyword arguments '{'pk': ''}' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)\\/like_action\\/$']
urls.py:
from django.contrib.auth.models import User
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.http import JsonResponse
from django.shortcuts import get_object_or_404, redirect, render
from django.utils import timezone
from django.views.decorators.csrf import csrf_exempt
def like_action(request, pk):
"""Like action: add +1 to post.like_button"""
post = get_object_or_404(Post, pk=pk)
post.like_button = post.like_button + 1
post.save()
return redirect('post_detail', pk=post.pk)
以下是&#39; post_detail&#39;的html代码。每当我尝试访问“post_detail”时,我总会收到错误消息。页。
from django.urls import path
from . import views
urlpatterns = [
path('keyboard', views.buttons, name='buttons'),
path('message', views.message, name='message'),
path('', views.post_list, name='post_list'),
path('<int:pk>/', views.post_detail, name='post_detail'),
path('post/new/', views.post_new, name='post_new'),
path('post/<int:pk>/edit/', views.post_edit, name='post_edit'),
path('about', views.about, name='about'),
path('post/<int:pk>/remove/', views.post_remove, name='post_remove'),
path('<str:category>', views.category_list, name='category_list'),
path('<int:pk>/like_action/', views.like_action, name='like_action'),
]
这是MySQL的结果:
{% extends 'blog/base.html' %}
{% load markdownify %}
{% load static %}
{% block content %}
<div class="post">
{% if post.created_date %}
<div class="date">
{{ post.created_date }}
</div>
{% endif %}
<h1 class="detail">{{ post.title }}</h1>
<div class="edit">
{% if user.is_authenticated %}
<a href="{% url 'post_edit' pk=post.pk %}">edit</a>
<a class="delete" href="{% url 'post_remove' pk=post.pk %}">delete</a>
{% endif %}
</div>
<div class="content">
{{ post.text|markdown|safe }}
</div>
<div class="interaction">
<p style="color: #4e57ac; display: inline; font-weight: bold; font-family: sans-serif;">
{{ post.like_button }}
</p>
{% if post.like_button < 2 %}
<a href="{% url 'like_action' pk=post.pk %}" style="font-weight: bold; font-family: sans-serif;">Like</a>
{% else %}
<a href="{% url 'like_action' pk=post.pk %}" style="font-weight: bold; font-family: sans-serif;">Likes</a>
{% endif %}
<div class="fb-share-button" data-href="http://leonkong.com{% url 'post_detail' pk=post.pk %}" data-layout="button" data-size="large" data-mobile-iframe="true"><a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fleonkong.com%2F&src=sdkpreparse" class="fb-xfbml-parse-ignore">Share</a></div>
</div>
</div>
{% endblock %}
views.post_detail
> DESC blog_post;
+--------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | 0 | |
| title | varchar(200) | NO | | NULL | |
| text | longtext | NO | | NULL | |
| created_date | datetime(6) | YES | | NULL | |
| author_id | int(11) | NO | | NULL | |
| category | varchar(5) | NO | | NULL | |
| like_button | int(11) | NO | | NULL | |
+--------------+--------------+------+-----+---------+-------+