Virtualenv 和 Django 应用程序不能很好地协同工作
我决定是时候将我的 django 项目迁移到 virtualenv 了。除了一件事之外,一切都运转良好。即使使用 pip 安装到我的 virtualenv 中的应用程序可以毫无问题地导入到我的项目中,但在运行开发服务器时找不到这些应用程序中的任何 .url、模板、模板标签等。
我检查了环境中的 python 路径,并且安装的 site-packages 目录位于路径中。
有人知道我可能做错了什么吗?
--- 添加信息 ---
由于我仍然遇到问题,我将向此票证添加更多信息。我确信这是我正在做的事情,只是不知道它是什么。从新环境开始,在 ubuntu 和 osx 上进行了测试。
virtualenv --no-site-packages testpjt
然后我使用 pip 添加 django 和 django smuggler。这是需求文本
-e svn+http://code.djangoproject.com/svn/django/trunk#egg=Django
django-smuggler==0.1.1-final
然后我用 pip 安装需求
pip install -E testpjt -r requirements.txt
一切似乎都安装得很好。因此,我启动虚拟环境并对文件进行以下更改:
source ../bin/activate
将 smuggler 添加到已安装的应用程序中:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'smuggler',
)
将 admin 和 smuggler 添加到 urls.py
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include('smuggler.urls')),
(r'^admin/', include(admin.site.urls)),
)
然后同步数据库并启动服务器:
../bin/python manage.py runserver 0.0.0.0:8000
我可以转到 ip/admin 并得到管理界面.. 我转到 ip/admin/load (转储,任何走私者 URL),然后得到 404。
为了测试,我可以输入 django shell 并:
from smuggler import urls
并且没有得到任何错误,所以我知道它们在那里。
如果我将走私者的副本放在项目目录的底部,它就可以正常工作。
I have decided that it was time to move to virtualenv for my django projects. All is working well except one thing. Even though the apps installed with pip into my virtualenv can be imported into my project without issue, any .urls, templates, template tags, etc. in those apps are not found when running the dev server.
I checked my python path in the environment and the site-packages directory with my installs are in the path.
Anyone know what I might be doing wrong?
--- added information ---
Since I am still having issues, I am adding more information to this ticket. I am sure it is something I am doing, just can't figure out what it is. Starting with a fresh environment, tested on both ubuntu and osx.
virtualenv --no-site-packages testpjt
Then I use pip to add just django and django smuggler. Here is the requirements text
-e svn+http://code.djangoproject.com/svn/django/trunk#egg=Django
django-smuggler==0.1.1-final
Then I install requirements with pip
pip install -E testpjt -r requirements.txt
Every thing seems to install fine. So I start the virtual environment and make the following changes to files:
source ../bin/activate
Add smuggler to installed apps:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'smuggler',
)
Add admin and smuggler to the urls.py
from django.conf.urls.defaults import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include('smuggler.urls')),
(r'^admin/', include(admin.site.urls)),
)
I then sync the db and start the server:
../bin/python manage.py runserver 0.0.0.0:8000
I can go to ip/admin and I get the admin interface.. I go to ip/admin/load (dump, any of the smuggler urls) and I get a 404.
For testing I can enter the django shell and:
from smuggler import urls
and get no errors, so I know they are there.
If I put a copy of smuggler in the base of my project directory it works just fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在运行开发服务器之前激活虚拟环境吗?
You are activating the virtual environment before running the dev server right?
这里的问题可能是您在虚拟环境之外安装 django-smuggler。
首先激活虚拟环境。
然后在 virtual-env 中安装 django-smuggler ,它应该可以正常工作。
The issue here might be that you are installing django-smuggler outside the virtual-env.
First activate the virtual-env.
Then install django-smuggler in virtual-env and it should work fine.