小编nab*_*don的帖子

Django不匹配URL中的unicode

我在django 2.0中遇到问题,其中包含unicode slug的url不匹配,我搜索了一种解决方案,但没有找到适合我的情况的解决方案,这是我的代码的简化版本:

// models.py

class Level(models.Model):
    name = models.CharField(max_length=100)
    slug = models.SlugField(max_length=100, allow_unicode=True)
Run Code Online (Sandbox Code Playgroud)

在我的url文件中,我具有以下模式:

// urls.py

urlpatterns = [
path('', views.index, name='index'),
path('level/<slug:level_slug>', views.level, name='level')]
Run Code Online (Sandbox Code Playgroud)

现在,如果我走,对http://127.0.0.1:8000/game/level/deuxième我说这个错误:

Request Method: GET
Request URL:    http://127.0.0.1:8000/game/level/deuxi%C3%A8me

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

game/ [name='index']
game/level/<slug:level_slug> [name='level']
admin/
accounts/
The current path, game/level/deuxième, didn't match any of these.
Run Code Online (Sandbox Code Playgroud)

但是,如果我将项目的slug更改为deuxieme不带unicode字符,则可以正常工作,有人知道该问题的解决方案吗?谢谢!

python django unicode python-3.x

6
推荐指数
2
解决办法
536
查看次数

在 Android 中展开 SearchView 后工具栏图标消失

这是我的问题:

我有一个漂亮的工具栏,其中的图标处于横向模式: 在此输入图像描述

展开搜索视图并显示弹出菜单后,会出现“添加”项(我认为不应该出现):

在此输入图像描述

然后用后退箭头键返回,如您所见,添加按钮如下:

在此输入图像描述

您将不再在弹出菜单中找到它: 在此输入图像描述

我正在使用 support:appcompat-v7:25.1.0,这是我的菜单代码:

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/app_bar_search"
        android:actionViewClass="android.support.v7.widget.SearchView"
        android:icon="@drawable/ic_action_search"
        android:title="Search"
        app:showAsAction="always|collapseActionView"
        android:enabled="true"
        android:visible="true"
        app:actionViewClass="android.support.v7.widget.SearchView"/>
    <item android:title="Add"
        android:enabled="true"
        android:icon="@drawable/ic_action_add"
        android:visible="true"
        app:showAsAction="ifRoom"
        android:id="@+id/add" />
    <item android:title="Settings"
        android:id="@+id/settings"
        app:showAsAction="never"
        android:icon="@drawable/ic_action_settings"
        android:enabled="true"
        android:visible="true" />
    <item android:title="Feedback"
        android:id="@+id/feedbvack"
        app:showAsAction="never"
        android:icon="@drawable/ic_action_feedback"
        android:enabled="true"
        android:visible="true" />

</menu>
Run Code Online (Sandbox Code Playgroud)

我可以将添加按钮 showAsAction 设置为“始终”,但我知道这是不鼓励的。这里有人知道为什么会出现这种行为吗?我怎样才能防止这种情况发生?

提前致谢。

android android-toolbar

4
推荐指数
1
解决办法
1624
查看次数

标签 统计

android ×1

android-toolbar ×1

django ×1

python ×1

python-3.x ×1

unicode ×1