问题描述
我是一名初级软件工程师,对 Django 很陌生.我构建了 这个应用程序,并且正在编写自述文件,向其他人解释如何分叉、克隆和设置应用程序在他们自己的机器上.我在尝试重新创建步骤时遇到了困难.
I am a junior software engineer and am quite new to Django. I built this app and am working on a README to explain to others how to fork, clone and setup the app on their own machines. I've gotten stuck while trying to re-create the steps.
这是我制定步骤的顺序:
This is the order in which I've drawn up the steps:
- 分叉并克隆存储库
- 获取虚拟环境
- Pip 安装要求.txt
- 获取access_token和secret_key并存储在secrets.sh中
- 设置 Postgres 数据库,创建用户 &数据库
- 迁移 (?) - 这就是我卡住的地方!
我尝试迁移应用,但没有可应用的迁移.
I tried migrating the app but there are no migrations to apply.
我试过 django-admin startproject ig_miner_app
.但我收到此错误代码:
I tried django-admin startproject ig_miner_app
. but am getting this error code:
CommandError:/Users/Erin/Desktop/CodeByEallard/project/instagram_miner/manage.py 已存在,将项目或应用程序覆盖到现有目录不会替换冲突文件
如果我能解决这个问题,我应该能够像平常一样运行服务器,对吧?
If I can get this sorted out, I should just be able to run the server like normal, right?
我确定我遗漏了一些东西(或很多东西),但不知道它们是什么.我觉得很傻,因为我显然能够首先创建应用程序,但无法弄清楚如何向其他人解释做同样的事情!有没有关于如何让服务器运行的建议?
I'm sure I'm missing something (or many things) but don't know what they are. I feel silly because I was obviously able to create the app in the first place, but can't figure out how to explain to someone else to do the same! Does any have suggestions for how to get the server to run?
谢谢!
推荐答案
首先,您收到该错误是因为您正在与克隆项目相同的目录中启动一个项目,该目录已经包含一个名为 ig_miner_app
因此名称冲突.
First off, you are getting that error because you are starting a project within the same directory as the cloned project, this directory already contains an app with the name ig_miner_app
hence the name conflict.
关于其他用户运行项目的步骤,这应该可行.
As regards steps to running the project by other users , this should work.
克隆项目
git clone https://github.com/erinallard/instagram_miner.git
创建并启动一个虚拟环境
create and start a a virtual environment
virtualenv env --no-site-packages
source env/bin/activate
安装项目依赖:
pip install -r requirements.txt
创建一个名为secrets.sh"的文件
create a file named "secrets.sh"
touch secrets.sh
(mac 和 linux)
touch secrets.sh
(mac and linux)
从 MiniWebTool 密钥中获取密钥并添加到 secrets.sh
obtain a secret from MiniWebTool key and add to secrets.sh
export SECRET_KEY='<secret_key>'
将 secrets.sh 添加到 .gitignore 文件
add secrets.sh to .gitignore file
创建一个 postgres 数据库并将凭据添加到 settings.py
create a postgres db and add the credentials to settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'db_name',
'USER': 'name',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
}
}
然后运行
python manage.py migrate
创建管理员帐户
python manage.py createsuperuser
然后
python manage.py makemigrations ig_miner_app
为应用程序进行迁移
然后再次运行
python manage.py migrate
启动开发服务器
python manage.py runserver
并在浏览器上打开 localhost:8000 以查看应用程序.
and open localhost:8000 on your browser to view the app.
我相信这应该可以让应用在其他机器上启动并运行.如果您遇到任何这些步骤,请告诉我,以便我进行编辑,如果没有,您可以使用它并添加我可能没有添加的任何其他相关信息.
I believe this should get the app up and running on others' machines. Let me know if you get stuck on any of these steps so I make edits, if not, you can just use it and add any other relevant info I might not have added.
这篇关于如何运行克隆的 Django 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!