练手小程序——无第三方依赖解析RSS

实现抓取RSS信息并简单解析后显示。提供搜索功能,可只显示相应关键字的RSS Items。无第三方jar包依赖。

package com.ojdbc;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.swing.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

/**
 * Created by Shengxinya on 2016/6/1.
 */
public class RSSSearcher extends JFrame {

    private final Map<String, List<String>> rssResMap = new HashMap<>();
    private final String searching = "正在抓取中……";
    private final String noRes = "无结果……";
    private JLabel urlLabel = new JLabel();
    private JTextField urlTF = new JTextField();
    private JLabel strLabel = new JLabel();
    private JTextField strTF = new JTextField();
    private JButton searchBn = new JButton();
    private JTextArea resTA = new JTextArea();


    /**
     * 解析URL对应的Rss中的items并放入对应Map中
     *
     * @param urlPath url路径
     */
    public void rssParser(String urlPath) throws IOException, ParserConfigurationException, SAXException {
        URL url = null;

        url = new URL(urlPath);

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = null;
        Document doc = null;
        List<String> list = new ArrayList<>(50);

        builder = dbf.newDocumentBuilder();
        doc = builder.parse(url.openStream());
        NodeList nList = doc.getElementsByTagName("item");
        for (int i = 0, j = nList.getLength(); i < j; i++) {
            list.add(nList.item(i).getTextContent());
        }

        rssResMap.put(urlPath, list);
    }

    /**
     * 初始化界面
     */
    public void init() {
        this.setSize(800, 600);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(new FlowLayout());
        this.setTitle("RssSearcher");
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
        urlLabel.setText("URL:");
        urlLabel.setSize(30, 40);
        this.add(urlLabel);
        urlTF.setColumns(30);
        this.add(urlTF);
        strLabel.setText("关键词:");
        strLabel.setSize(30, 40);
        this.add(strLabel);
        strTF.setColumns(25);
        this.add(strTF);
        searchBn.setText("Search");
        searchBn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                doSearch();
            }
        });
        this.add(searchBn);
        resTA.setColumns(65);
        resTA.setEnabled(false);
        resTA.setRows(30);
        resTA.setAutoscrolls(true);
        resTA.setLineWrap(true);
        resTA.setWrapStyleWord(true);

        JScrollPane scroll = new JScrollPane(resTA);
        scroll.setHorizontalScrollBarPolicy(
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll.setVerticalScrollBarPolicy(
                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

        this.add(scroll);
        this.setVisible(true);
    }

    /**
     * Search处理方法
     */
    public void doSearch() {
        if (isEmpty(urlTF.getText())) {
            return;
        }
        searchBn.setEnabled(false);
        String str = strTF.getText();
        CountDownLatch fcdl = new CountDownLatch(1);
        new Thread() {
            public void run() {
                resTA.setText(searching);
                //同一url不用再次请求
                if (!rssResMap.containsKey(urlTF.getText())) {
                    try {
                        rssParser(urlTF.getText());
                    } catch (Exception e) {
                        e.printStackTrace();
                        fcdl.countDown();
                        return;
                    }
                }
                List<String> list = rssResMap.get(urlTF.getText());
                if (list == null || list.size() == 0) {
                    return;
                }
                resTA.setText("");
                for (String itemText : list) {
                    if (isEmpty(strTF.getText()) || itemText.contains(str)) {
                        resTA.setText(resTA.getText() + itemText);
                    }

                }
                fcdl.countDown();
            }
        }.start();
        try {
            fcdl.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (isEmpty(resTA.getText()) || resTA.getText().equals(searching)) {
            resTA.setText(noRes);
        }
        searchBn.setEnabled(true);
    }

    /**
     * 判断给定字符串是否为空
     *
     * @param str 给定字符串
     * @return 是否为空
     */
    public boolean isEmpty(String str) {
        return str == null || "".equals(str);
    }

    public static void main(String[] args) {
        RSSSearcher searcher = new RSSSearcher();
        searcher.init();
    }
}

 

 

发表在 技术, 未分类 | 留下评论

Apache2.4 屏蔽恶意IP访问

最近一直在外地出差,手头的事情挺多,没有多少时间来更新博客。不过最近几次访问博客都出现了错误“Error establishing a database connection”。

看到这个第一反应是被黑了!这个提示连接不到数据库。马上登录到网站后台,首先查看mysql服务是否还健在, 果然,mysql已经down了。先把服务启动起来再说。 然后到/var/log/mysql下查看error.log,只是发现有异常启动关闭的提示却没有其他信息。

登录控制台,打开WP统计插件的统计页面。一看吓一跳,今天的访问量纠结超过了2W次,而在线人数才4个。mysql应该是被这几个ip给耗尽连接爆掉了。

首先先禁止这几个ip访问吧。

修改网站根目录下的.htaccess文件(Apache2.4),添加以下几行

<RequireAll>
require all granted
require not ip 185.103.252.170
require not ip 185.130.4
require not ip 159.122.224.173
</RequireAll>

重启后,经常可以临时先禁止这几个ip的访问。查看/var/log/apache2/error.log文件,发现有刷出以下信息:

[Thu Apr 28 07:38:55.840256 2016] [authz_core:error] [pid 13605] [client 185.103.252.170:58768] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:38:57.252238 2016] [authz_core:error] [pid 13602] [client 185.130.4.120:37930] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:38:57.278486 2016] [authz_core:error] [pid 13597] [client 185.103.252.170:50045] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:38:58.640261 2016] [authz_core:error] [pid 13644] [client 159.122.224.173:57701] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:38:58.765086 2016] [authz_core:error] [pid 13643] [client 185.130.4.197:35913] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:38:58.831950 2016] [authz_core:error] [pid 13605] [client 159.122.224.173:57239] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:38:59.038847 2016] [authz_core:error] [pid 13602] [client 185.130.4.197:39839] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:39:00.046314 2016] [authz_core:error] [pid 13597] [client 185.130.4.197:54025] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:39:00.186308 2016] [authz_core:error] [pid 13644] [client 185.130.4.197:55952] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:39:00.874022 2016] [authz_core:error] [pid 13643] [client 185.130.4.120:34832] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:39:01.448978 2016] [authz_core:error] [pid 13605] [client 185.130.4.120:43444] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php
[Thu Apr 28 07:39:02.429121 2016] [authz_core:error] [pid 13602] [client 185.130.4.197:60332] AH01630: client denied by server configuration: /var/www/wordpress/xmlrpc.php

看来真是锲而不舍呀。再结合之前统计里面的访问量最高的页面是xmlrpc.php(>2w6)。而这个页面一般用不着,但是却是针对Wp的一个很著名的攻击手段。看来不能光封ip了,这个页面也得禁用下了。继续修改.htaccess文件,增加以下内容:

<Files xmlrpc.php>
Require all denied
</Files>

禁止所有访问该页面的请求。重启Apache2后,直接访问该页面已经“Forbidden”了。

另外请一定注意,要将添加的内容放置在写在“# BEGIN WordPress”和”# END WordPress”之外,防止在修改固定链接时被覆盖。

 

发表在 技术, 未分类 | 标签为 , , | 一条评论

Docker学习笔记(1)

 

一、Docker是什么?

Docker是一个新的容器化的技术,它轻巧,且易移植,号称“build once, configure once and run anywhere。

Docker 组件与元素

Docker有三个组件和三个基本元素

  • 三个组件为:
  1. Docker Client 用户界面,负责与Deanmon通信
  2. Docker Deamon 运行与主机之上,处理服务请求
  3. Docker index 是中央registry,支持拥有公有与私有访问权限的Docker容器镜像的备份。
  • 三个基本元素
  1. Docker  Containers 负责应用程序的运行,包括操作系统、用户添加的文件以及元数据。
  2. Docker Images 是一个只读模板,用来运行Docker容器
  3. Docker File 是文件指令集,用来说明如何自动创建Docker镜像。

Docker简单使用

 

#从公有库中创建一个容器,busybox是一个最小的linux系统,包含常用的命令
docker pull busybox 

#在busybox容器中调用echo命令,打印“Hello World”
docker run busybox /bin/echo Hello world

#以后台进程方式运行命令
sample_job=$(docker run -d busybox /bin/sh -c "while true; do echo Docker; sleep 1; done")

#以docker logs的方式查看job的当前状态
docker logs $sample_job

#停止任务
docker stop $sample_job

#重新启动
docker restart $sample_job

#完全移除,stop后使用rm命令
docker stop $sample_job 

docker rm $sample_job

#保存容器为镜像
docker commit $sample_job job1 

#其他命令请参见 docker help

 

 

发表在 技术, 未分类 | 标签为 | 留下评论

重复造轮子——DataLoader,导入数据文件到数据库表

以前一直使用SQLLoader及PL/SQL Dev导入文本文件Oracle的数据库表。其中SQLLoader导入速度飞快,但是需要Oracle服务端工具支持,在客户端无法直接安装使用。在测试环境中经常将数据文件sftp到服务器上,然后在服务器上执行。而sftp过程中,遇到过以二进制模式传文件时,文件中的分隔符会多出换行符,导致导入出错(文本文件就要以文本模式传输,不要用二进制模式)。而使用PL/SQL Dev导入的话,采用“Text Importer”小文件速度挺快,大文件经常会导致PL/SQL Dev 死掉,且不知道当前导入状态。导致导入文件时不敢点击PL/SQL Dev,一点就死……

前两天又要导入一批文本数据到数据库,不想安装Oracle服务端,便想着写一个小工具来模拟SQLLoader的功能(当然,SQLLoader性能很高,也不是直接执行insert  sql)。

于是一个名为 DataLoader 的工具就产生了,有兴趣的可以看看。之所以重复造轮子,一方面好久没写代码练练手,另一方面,我真的很闲……

好吧,继续说工具。它采用了多线程批量提交的方式,支持一次导入一个文件夹内的所有数据文件。每个文件一个解析线程,每个解析线程一个入库线程。

约束:

  1. 需要文件名前缀与表名一致;
  2. 需要标题行列名与表结构一致;
  3. 所有标题列要在表中存在,且必须导入到表中。目前不支持只导入部分列。
  4. 目前只支持Oracle数据库
  5. ……

 

发表在 技术, 未分类 | 标签为 , , , | 留下评论

SpringMVC+Mybatis整合实例

web.xml

<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
    <display-name>Archetype Created Web Application</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mybatis.xml</param-value>
    </context-param>
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <async-supported>true</async-supported>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- Spring MVC servlet -->
    <servlet>
        <servlet-name>SpringMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringMVC</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

spring-mvc.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    <context:component-scan base-package="com.ojdbc.hello"/>

    <mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <bean class="org https://viag....from-uk/.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

spring-mybatis.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-3.1.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
    <context:component-scan base-package="com.ojdbc"/>
    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties"/>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource"
          destroy-method="close">
        <property name="driverClassName" value="${driver}"/>
        <property name="url" value="${url}"/>
        <property name="username" value="${username}"/>
        <property name="password" value="${password}"/>
        <property name="initialSize" value="${initialSize}"></property>
        <property name="maxTotal" value="${maxActive}"></property>
        <property name="maxIdle" value="${maxIdle}"></property>
        <property name="minIdle" value="${minIdle}"></property>
        <property name="maxWaitMillis" value="${maxWait}"></property>
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="mapperLocations" value="classpath:com/ojdbc/hello/**/*-mapping.xml"/>
    </bean>

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.ojdbc.hello.dao"/>
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>

    <bean id="transactionManager"
          class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

</beans>

完整例子下载:

SpringMVCTest

发表在 技术, 未分类 | 标签为 , , , | 留下评论

SpringMVC在IE下提示下载json

之前使用的配置如下:

<mvc:annotation-driven />
  <bean id="mappingJacksonHttpMessageConverter"
       class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
     <property name="supportedMediaTypes">
         <list>
             <value>text/html;charset=UTF-8</value>
         </list>
     </property>
 </bean>

 
  <bean  class=" org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
      <property name="messageConverters">
          <list>
              <ref bean="mappingJacksonHttpMessageConverter" /> 
          </list>
      </property>
  </bean>

 

采用以下配置(Fastjson,如果用Jackson替换相应类)即可解决:

<mvc:annotation-driven>
        <mvc:message-converters>
            <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <property name="supportedMediaTypes">
                    <list>
                        <value>text/html;charset=UTF-8</value>
                    </list>
                </property>
            </bean>
        </mvc:message-converters>
 </mvc:annotation-driven>

 

 

发表在 技术, 未分类 | 标签为 , | 留下评论

SpringMVC+Mybatis异常解决

今天在IDEA(Maven)整合SpringMVC和Mybatis时,在Spring-mybatis.xml中设置了自动扫描mapping.xml文件。配置如下

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="mapperLocations" value="classpath:com/ojdbc/hello/mapping/*.xml"></property>
</bean>

结果在启动Tomcat时报错(省略部分代码):

[org.springframework.web.context.support.XmlWebApplicationContext] - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/ojdbc/hello/mapping/*.xml]: class path resource [com/ojdbc/hello/mapping/] cannot be resolved to URL because it does not exist
[org.springframework.web.context.ContextLoader] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/ojdbc/hello/mapping/*.xml]: class path resource [com/ojdbc/hello/mapping/] cannot be resolved to URL because it does not exist
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)

从异常信息行:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring-mybatis.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [org.springframework.core.io.Resource[]] for property 'mapperLocations'; nested exception is java https://pharmacieinde...ce.lang.IllegalArgumentException: Could not resolve resource location pattern [classpath:com/ojdbc/hello/mapping/*.xml]: class path resource [com/ojdbc/hello/mapping/] cannot be resolved to URL because it does not exist

从后往前看,最根本的原因是不能将“classpath:com/ojdbc/hello/mapping/*.xml”转成URL。再往前看发现是不能由于不能识别正则通配符“*”。

经测试将“classpath:com/ojdbc/hello/mapping/*.xml”修改成“classpath*:com/ojdbc/hello/mapping/*.xml”后问题解决。

后来访问页面时又提示异常:

java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for demo1

 

分析其原因应该是没找到mapping.xml文件,导致mybatis不能访问到要执行的sql。

结合两个问题及生成的war包,应该是Maven在生成war包时没有将源码包中的xml文件添加到war包中,导致运行时找不到所对应的mapping文件。

猜测原因:使用“classpath*”的方式引入mapping文件是不会立刻验证文件是否存在,而不带星号的在初始化时就会验证文件是否存在,导致刚开始的时候出错。

解决方法为在Maven的pom.xml中增加以下代码:

<build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
    </build>

而此时classpath可以直接使用,不用加星号

发表在 技术, 未分类 | 留下评论

Execution failed for task ‘:app:transformClassesWithDexForDebug’

Clean Project and retry

发表在 技术, 未分类 | 标签为 , | 一条评论

DjangoUeditor ImportError: No module named ‘widgets’

环境:Python 3.4.3|Django 1.9.2

最近在学习Django框架,按照网上教程集成DjangoUeditor时,出现错误,错误提示为:

from widgets import UEditorWidget,AdminUEditorWidget
ImportError: No module named ‘widgets’

经查发现,DjangoUeditor是基于Python 2.7的,对Python3的支持有问题。导致widgets.py文件出错,不能import。解决方法为修改widgets.py或者采用网上修改好的版本DjangoUeditor3

鸣谢:涂伟忠

发表在 技术 | 标签为 , , , | 留下评论

WordPress设定固定链接为postname时404

【环境:Ubuntu 14.04 x64|Apache 2.4.7|WordPress4.4中文版】

之前我的WordPress固定链接设置的为“朴素”,后来在进行seo生成sitemap时需要更改为postname。设置好后,访问所有文章都转到404页面,刚开始以为是中文编码问题,安装了WP Slug Translate插件,然后还是404。以“WordPress 固定链接 404”为关键字在网上搜索。找到好多链接,基本上都是修改“.htaccess”文件权限、修改httpd.conf。按照网上的方法,修改文件权限,并将wordpress目录授予www-data用户(我的之前为登陆用户非www-data用户)

sudo chown -R www-data  /var/www/wordpress
sudo chmod 666 .htaccess

然后修改/etc/apache2/sites-available/000-default.conf文件,在VirtualHost节点内新增以下代码

<Directory /var/www/wordpress>
           Options FollowSymLinks
           AllowOverride All
 </Directory>

然后 sudo /etc/init.d/apache2 restart 重启apache2

结果错误依旧。

查看/etc/apache2/mods-available目录,发现有rewrite.load文件,查看内容发现指向的so文件也存在。转到/etc/apache2/mods-enabled目录发现没有rewrite.load的链接。看来找到文件的原因了,应该是apache2.4.7默认没有载入重定向的模块,这样就好办了。

sudo ln -s ../mods-available/rewrite.load  rewrite https://ci....in-uk/.load
sudo /etc/init.d/apache2 restart

刷新页面后,解决。

 

发表在 技术, 未分类 | 标签为 , , | 2条评论