Been struggling with these Django projects won't deploy. Kindly help. Please

^^^^^^^^^^^^^^^^^^^^^^ File "/opt/venv/lib/python3.11/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application django.setup(set_prefix=False) File "/opt/venv/lib/python3.11/site-packages/django/init.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/opt/venv/lib/python3.11/site-packages/django/apps/registry.py", line 91, in populate app_config = AppConfig.create(entry) ^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/venv/lib/python3.11/site-packages/django/apps/config.py", line 178, in create mod = import_module(mod_path) ^^^^^^^^^^^^^^^^^^^^^^^ File "/root/.nix-profile/lib/python3.11/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1206, in _gcd_import File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1206, in _gcd_import File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked ModuleNotFoundError: No module named 'pages' [2023-07-11 13:31:27 +0000] [9] [INFO] Worker exiting (pid: 9) [2023-07-11 13:31:28 +0000] [1] [INFO] Shutting down: Master [2023-07-11 13:31:28 +0000] [1] [INFO] Reason: Worker failed to boot.
Solution:
Try this: gunicorn --chdir blogy 'blogy.wsgi'
Jump to solution
127 Replies
Percy
Percy13mo ago
Project ID: N/A
maxralph01
maxralph0113mo ago
N/A
root
root13mo ago
Could you send your code?
.scapino
.scapino13mo ago
Runs okay locally?
maxralph01
maxralph0113mo ago
Yes. It runs okay locally
maxralph01
maxralph0113mo ago
So sorry for the late reply. I was still trying it. It still does not work. Here is the code repo on GutHub. https://github.com/blogy
GitHub
blogy - Overview
GitHub is where blogy builds software.
maxralph01
maxralph0113mo ago
root
root13mo ago
Could you send the repository?
maxralph01
maxralph0113mo ago
GitHub
blogy - Overview
GitHub is where blogy builds software.
root
root13mo ago
That's a 404. That's an empty profile.
maxralph01
maxralph0113mo ago
I am sorry
maxralph01
maxralph0113mo ago
GitHub
GitHub - maxralph1/gem-inn: Gem-Inn is an ecommerce online store fo...
Gem-Inn is an ecommerce online store for a jewelries and clothing shop crafted in Django (Python), vanilla JavaScript and Bootstrap 5.3 with online payment channels - GitHub - maxralph1/gem-inn: Ge...
maxralph01
maxralph0113mo ago
GitHub
GitHub - maxralph1/blogy: BlogySocial is a SOCIAL MEDIA/BLOG applic...
BlogySocial is a SOCIAL MEDIA/BLOG application crafted in Django (python), vanilla JavaScript and Bootstrap 5.3 - GitHub - maxralph1/blogy: BlogySocial is a SOCIAL MEDIA/BLOG application crafted in...
maxralph01
maxralph0113mo ago
Those 2 It is specifically refusing to deploy on Railway
root
root13mo ago
Hmm, I don't really know a thing about Django, so I'm going to ping in @Vin - when you're around, would you mind helping?
maxralph01
maxralph0113mo ago
I am here Oh
Brody
Brody13mo ago
you've sent two repos, do they both fail with the exact same logs?
maxralph01
maxralph0113mo ago
Yes The exact same logic Both I have been redoing this since yesterday. Halted everything else I was supposed to do
.scapino
.scapino13mo ago
I think the problem is in the WSGI setup Your Procfile says gunicorn 'blogy.blogy.wsgi' But if you run that command locally, you'll see the same startup error. Fix that locally, and I expect it'll deploy correctly.
MantisInABox
MantisInABox13mo ago
At a quick glance of the blogy repo, I think I might have found the issue, but if you give me about 15 minutes, I can test to make sure that’s what the problem is.
Solution
.scapino
.scapino13mo ago
Try this: gunicorn --chdir blogy 'blogy.wsgi'
maxralph01
maxralph0113mo ago
I have tried blogy.wsgi. It failed Thank you so much. I am patiently waiting. ok. I do it right away. It didn't work instantly FAILED Deployment Failed during build process That's the error message
Brody
Brody13mo ago
please provide full build logs in a .txt file
maxralph01
maxralph0113mo ago
ok
.scapino
.scapino13mo ago
Hey maxralph, I tried deploying blogy from your repo after changing Procfile from web: gunicorn 'blogy.blogy.wsgi' to web: gunicorn --chdir blogy 'blogy.wsgi' -- works for me. maybe doublecheck your changes?
maxralph01
maxralph0113mo ago
wow You used Railway?
.scapino
.scapino13mo ago
Failed the first time for be because I made a typo (blog instead of blogy), but it's working on Railway, yes
maxralph01
maxralph0113mo ago
I try it right now
.scapino
.scapino13mo ago
I hope your issue is also just a typo. Those are the worst
Brody
Brody13mo ago
yeah last edit to either of those Procfiles are from yesterday
maxralph01
maxralph0113mo ago
Can I send it here?
Brody
Brody13mo ago
please remove any build or start commands you may have set in the service settings no it's okay, nevermind, I'm pretty sure I know what went wrong very important!!
maxralph01
maxralph0113mo ago
I have made many commits on it. SO I had to open a new app. In fact, I recreated it from scratch, thinking it was the issue. Let me make it Public and send you the link
maxralph01
maxralph0113mo ago
GitHub
GitHub - maxralph1/blogysocial
Contribute to maxralph1/blogysocial development by creating an account on GitHub.
Brody
Brody13mo ago
thank you and to double check, do you have any build or start commands defined in the service settings?
maxralph01
maxralph0113mo ago
no I am trying the latest command. it is now loading up. Wow No more error messages Let me change the settings file to point to the domain Let us see if it is the recent problem of it not showing up
MantisInABox
MantisInABox13mo ago
So, there are a few things you can do... The easiest would be to make the Procfile change with the --chdir flag. The other is a bit more involved, but is also best practice for django projects, ti move all subfolders to the root of your repo. Normally, you would not have your entire project inside of a folder. And then use a railway.json file instead of Procfile.
maxralph01
maxralph0113mo ago
It is finally up I owe you all a lot! I wish I can pay I am using this to apply for a job
Brody
Brody13mo ago
I wish you good luck!
MantisInABox
MantisInABox13mo ago
Can't pay us directly, but you pay Railway, so that's good enough!
maxralph01
maxralph0113mo ago
ANyways, there is a problem right now. It is showing my Django logic errors
MantisInABox
MantisInABox13mo ago
When you visit your domain?
maxralph01
maxralph0113mo ago
I will try to debug those errors Yes https://blogysocial.up.railway.app/ Here. That's it.
MantisInABox
MantisInABox13mo ago
Then, you need to change your settings.py file from DEBUG=True to DEBUG=False
Brody
Brody13mo ago
say the thing vin
MantisInABox
MantisInABox13mo ago
You never want to deploy code in DEBUG mode
maxralph01
maxralph0113mo ago
No. I only want to see if there are errors, before I turn it to False As I am still developing it
MantisInABox
MantisInABox13mo ago
Right, that's what you would do on local with the built-in Django server... Not on production.
.scapino
.scapino13mo ago
Oh, is it missing the SQLite db file?
Brody
Brody13mo ago
or the migrations
maxralph01
maxralph0113mo ago
I thought about it, but I kept including it
root
root13mo ago
looks like you need to run your migrations
maxralph01
maxralph0113mo ago
I checked the miobgrations right now It is up-to-date
MantisInABox
MantisInABox13mo ago
If you are using SQLite, you will need to be on priority boarding, and use volumes, otherwise each deploy will destroy your database. I would suggest switching to Postgres, or enabling volumes with priority boarding
maxralph01
maxralph0113mo ago
Oh Sorry
root
root13mo ago
switch to postgres, it's just better
maxralph01
maxralph0113mo ago
I saw it included in my .gitignore file Yes. I plan to after it starts working
Brody
Brody13mo ago
yes, please switch to postgres
MantisInABox
MantisInABox13mo ago
https://github.com/railwayapp-templates/django I would check this out too at some point for best practices on how to setup your django project on railway
maxralph01
maxralph0113mo ago
And I will put all env atrributes hidden on Railway settings Thank you Definitely
MantisInABox
MantisInABox13mo ago
what thing?
Brody
Brody13mo ago
"switch to postgres" you said it 🙂
MantisInABox
MantisInABox13mo ago
🤣 It's not my fault Postgres is the superior database
maxralph01
maxralph0113mo ago
yes. I will. just redeployed it with the sqlite.
Brody
Brody13mo ago
real
maxralph01
maxralph0113mo ago
it is loading
Brody
Brody13mo ago
sqlite is not postgres
maxralph01
maxralph0113mo ago
I am short of words You all will remain blessed
Brody
Brody13mo ago
I am short and short of words
maxralph01
maxralph0113mo ago
If you check the line of commits, it was getting out of hand. so much that I had to create another app entirely today. I was scared that any employer seeing the main file with that many iunimportanty commits would think me reckless That was why I opened a new repo entirely to hide my problems The app is now running Thank you so much once again 58 commits in total
MantisInABox
MantisInABox13mo ago
It's development... You're going to commit bad code from time to time. It's just the nature of the beast
maxralph01
maxralph0113mo ago
Plus all the commits I had to force-drop from the list on the Blogy main app Yes. But for hosting, the employer may ask if I couldn't use a clone to test thye deployment
Brody
Brody13mo ago
I understand your concern, and that's why I don't use github 🙂 use github though (do as I say not as I do)
maxralph01
maxralph0113mo ago
Thank you all for your precious time. I really appreciate.
.scapino
.scapino13mo ago
Now I have to look up how to make Postgres work on Railway, and what’s in a railway.json file. My curiosity is piqued!
MantisInABox
MantisInABox13mo ago
Go look at https://github.com/railwayapp-templates/django Shows you everything you need to use both
maxralph01
maxralph0113mo ago
You can make an instance of it. Copy the credentials.
MantisInABox
MantisInABox13mo ago
Also, you can think of the railway.json file as a new and improved Procfile.
maxralph01
maxralph0113mo ago
Ok. Thank you. I just opened it.
MantisInABox
MantisInABox13mo ago
You can set restart policy and a few other things.
maxralph01
maxralph0113mo ago
Ok Ok I just starred it so that I can always refer to it anytime I forget after using it for these deployments. Thank you once more. I appreciate.
MantisInABox
MantisInABox13mo ago
Anytime.
maxralph01
maxralph0113mo ago
I will leave this thread open if you do not mind I wish to deploy my Node.JS, React.JS and Laravel apps too
Brody
Brody13mo ago
yeah for sure, I'll mark as solved though
maxralph01
maxralph0113mo ago
Also, I do not know if Railway accepts Phoenix framework Because I have a little app built in it
MantisInABox
MantisInABox13mo ago
Phoenix, with Elixr?
maxralph01
maxralph0113mo ago
OK Yes
MantisInABox
MantisInABox13mo ago
Yeah, you should be able to deploy an Elixr app
maxralph01
maxralph0113mo ago
Thank you
MantisInABox
MantisInABox13mo ago
Elixir | Nixpacks
App source + Nix packages + Docker = Image
maxralph01
maxralph0113mo ago
OK Bookmarkedd alos. Thank you. also* One more question, if you have the time. I am pushing it right away with Postgres. But I must run some commands on the terminal. The command of creating a superuser. Can I also add the command to the Procfile? It seems practically impossible I see CLI]
MantisInABox
MantisInABox13mo ago
You would wnat to use the railway CLI, which will inject the environment variables to your local shell. This will allow you to run the command locally, using the settings from Railway
maxralph01
maxralph0113mo ago
But the documentation does not really seem straightforward enough OK I'll go through it again
Brody
Brody13mo ago
note, this only works with postgres
MantisInABox
MantisInABox13mo ago
Use the railway shell for that.
maxralph01
maxralph0113mo ago
Ok PS C:\Users\maxim> railway shell No service linked, not entering shell. PS C:\Users\maxim> railway link ? Select a project
lively-robin
pure-shirt dusty-glove [↑↓ to move, enter to select, type to filter] The 'railway link' shows up But the 'railway shell' doesn't show me nothing
Brody
Brody13mo ago
firstly you need to be in your project folder
maxralph01
maxralph0113mo ago
Yes I have tried going into it
Brody
Brody13mo ago
and you are not according to the text above
maxralph01
maxralph0113mo ago
And when i use the command 'ls', it shows me my computer folder I have tried cd
MantisInABox
MantisInABox13mo ago
You need to link your project, and then do the railway shell
maxralph01
maxralph0113mo ago
it CDs into my local
Brody
Brody13mo ago
yes of course, this is a local shell, just with the railway service variables
maxralph01
maxralph0113mo ago
I have done the link too
MantisInABox
MantisInABox13mo ago
What Brody said
Brody
Brody13mo ago
what Brody said
MantisInABox
MantisInABox13mo ago
You cannot connect into the container
maxralph01
maxralph0113mo ago
Unfortunately so
Brody
Brody13mo ago
afortunately so**
maxralph01
maxralph0113mo ago
How can I run Django commands?
Brody
Brody13mo ago
with railway shell
MantisInABox
MantisInABox13mo ago
You would run the railway shell, then run the Django commands like you normally would during development
maxralph01
maxralph0113mo ago
No service linked, not entering shell.
Brody
Brody13mo ago
run railway service
maxralph01
maxralph0113mo ago
That is what it tells me Whenever I do 'railway shell'
Brody
Brody13mo ago
^
maxralph01
maxralph0113mo ago
This command showed me the project folder But when I tried running the django commands, it failed again
MantisInABox
MantisInABox13mo ago
You can always manually set your railway environment variables in your virtual environment on your local system. It mainly will only need your Postgres variables
maxralph01
maxralph0113mo ago
Yes But the app has to have the admin user set OK Wait I just figured out something' Since the Postgres is hosted differently and uses internet to connect, then, no problem This will solve it
Brody
Brody13mo ago
correct
maxralph01
maxralph0113mo ago
Sorry. My brain has been clogged. I have been on this since morning. This is more than 15 hours now looking at the screen Sorry about that
Brody
Brody13mo ago
no worries, we all start somewhere
MantisInABox
MantisInABox13mo ago
I’ve been there before. 20+ hours searching for misspelled variable names
Brody
Brody13mo ago
the pain is real
maxralph01
maxralph0113mo ago
oh
Adam
Adam13mo ago
Write a script compiling all your variable names then check for common misspellings programatically