小编Cri*_*owi的帖子

如何在Django中获取登录用户的用户名?

如何在Django应用程序中获取有关登录用户的信息?

例如:

我需要知道登录用户的用户名,说明谁发布了评论:

<form id='formulario' method='POST' action=''>
    <h2>Publica tu tuit, {{ usuario.username.title }} </h2>
    {% csrf_token %}
    {{formulario.as_p}}
    <p><input type='submit' value='Confirmar' /></p>
</form>
Run Code Online (Sandbox Code Playgroud)

usuario.username.title我获取用户名时,但在模板中,我需要从视图中获取该信息.

谢谢.=)

python django django-templates models django-views

52
推荐指数
5
解决办法
10万
查看次数

没有在heroku中运行Django的Web进程

我试图在heroku中部署我的应用程序,但是当我最终尝试在heroku中运行我的应用程序时,我会在浏览器中执行此操作:

Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.
Run Code Online (Sandbox Code Playgroud)

当我看到我的日志时,我得到了下一个:

2013-08-31T19:53:30.672416+00:00 heroku[api]: Enable Logplex by user@example.com
2013-08-31T19:53:30.700218+00:00 heroku[api]: Release v2 created by user@example.com
2013-08-31T19:58:41+00:00 heroku[slug-compiler]: Slug compilation started
2013-08-31T20:04:12.967456+00:00 heroku[router]: at=info code= desc="Blank app" method=GET path=/ host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= service= status=502 bytes=
2013-08-31T20:04:13.161016+00:00 heroku[router]: at=info code= desc="Blank app" method=GET path=/favicon.ico host=cristowip.herokuapp.com fwd="189.137.81.39" dyno= connect= …
Run Code Online (Sandbox Code Playgroud)

python deployment django heroku

7
推荐指数
3
解决办法
2万
查看次数

如何为用户模型Django创建自定义表单

我想在Django中为django.contrib.auth.models.User的用户创建创建自己的表单,但我找不到一个好例子.有人能帮我吗?

python forms django

2
推荐指数
1
解决办法
1731
查看次数

Django无法在/ media /文件夹中看到图像

如果我将我的图像放在/media/文件夹中,它就不起作用.但是,如果我把它们放在'/ static /'文件夹中就可以了.

{% extends 'base.html' %}

{% block contain %}
    <h1>New Report</h1>
    <form id="create" method="POST" action="" enctype="multipart/form-data">{% csrf_token %}
        {{ form.as_p }}
        <input type="submit" value="Confirm">
    </form>


    {% for report in reports %}
        <P> {{report.title}} </P> <br>
        <img src="{{STATIC_URL}}<name of the image>" width='100px' height='100px'> =====> I can see the image

        <img src="{{MEDIA_URL}} <name of the image>" width='100px' height='100px'> =====> I cant see the image

        <img src="/static/<name of the image>" width='100px' height='100px'> =====> I cant see the image

        <img …
Run Code Online (Sandbox Code Playgroud)

python django templates image

0
推荐指数
1
解决办法
3063
查看次数