I have been thinking long and hard about making this post and after hours of Google searches I couldn't come up with any good sources so thought I'd ask here.
I am relatively new to coding, started early this year and started a software programming degree so I am super keen to learn. I have managed to make a fully working project that works on shared hosting but doesn't allow me to use latest packages and modules that is why I upgraded to a VPS. But editing my project on cPanel on a shared hosting was alot less scary than what I'm attempting now.
I've recently purchased a VPS to host my first django project I'm building for my father, the project is basically a gallery that allows him to upload a blog and images. I had a standard shared hosting plan which was fine but I couldn't use latest python and django on it.
So what I want to ask is; what is the common practice for starting off with building a project on ubuntu? In my head it was building it on VSCode and just transferring it to ubuntu, linking it to my domain and BAM.
I've found writing the code very tedious and difficult on ubuntu terminal, using cd to go in and out of folders, copy and paste not working etc. so Is writing it on local pc using VSCode acceptable?
How would static files be stored for my father when he uploads his images/blogs, do they store on the VPS or do I need to link something like AWS which is what I really wanted to avoid when getting a VPS.
I would even appreciate just a step by step list of a common procedure for a project as I have described above.
I appreciate anybody and everybody who is willing to give up some time to help me here.
Many Thanks.
Try this guide here. It is a beginner friendly approach to setup django:
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-22-04
Related
I built a (relatively simple) Django project following a tutorial (the recently released Hello Web App book.) I committed my changes along each step of the way, and I have my working solution in a github repo. However, when I clone the code into a new work space such as onto a new machine or into a new slot on a cloud IDE, the app doesn't work. I get a few errors and with each I resolve, another pops up. Basically, my environment is totally messed up and incompatible with the app beyond having Python and Django both installed.
I realize that I can read through the error messages I get when I invoke runserver, solve each one by one, etc. but it seems there should be a cleaner/simpler way to be able to pull down my repo to a fresh workspace and have it up and running in just a minute or two. I've read recommendations about using virtualenv, but it also seems like people discourage including venv inside your repo because of the extraneous commits and added bulk that will result from it so I don't think that actually solves my problem of trying to reduce new workspace configuration effort.
Perhaps I am overly optimistic, but I'm hoping someone can give me a recommendation to avoid the need to workout these kinks each time I start fresh.
So I was looking at the Getting Started with Django http://gettingstartedwithdjango.com/ tutorial, and everything was done in a vm. The author set up a vm, and then created a virtualenv in the vm. Is this good practice to get started on a django project, or software projects in general? Why the need for a vm? What happens if I have more than one project - should I use two vms? Or just create additional virtualenvs in the original vm?
I'm still a student in school, and I'm working on my own personal side projects, so it'd be useful to get some input on how things are really done in the real world.
Thanks!
You do not need VMs. You can get through just fine using virtualenv with an environment for each project - especially just starting out in Django.
In the future, one of the times you may need a separate VM environment for your project is if it has a lot of unique infrastructure needs. It's much easier to setup a VM, setup the unique environment, and not have to alter it when you want to work on other projects.
Another common reason I see people using VMs is when they have a Windows machine but want to develop in Linux. It's easy to spin up a Linux VM and work there since Linux is more programmer friendly.
It's subjective. I leverage virtualenv and virtualenvwrapper for my development, which I do on Linux. There are instance where you might need to leverage two separate VMs...it just depends, although I haven't encountered this.
There's no unwritten rule that says you have to use a VM. Python (and many other languages/frameworks) simply work better on Linux, so many people will leverage VMs to run Linux on Windows or Mac to do their development in that environment.
I've been fortunate enough to discover django_compressor and implemented it within our stack, which deploys to many servers (Currently 6, but growing as we deploy smaller virtual machines.)
Now this is all fine and dandy if you're using django_compressor at its finest. Compressing raw CSS/JS code
However, say now I want introduce some type of pre-compiler. Let's say for this example it is LESS (css). The thought process for this is fairly simple:
Install node, npm, and the less package onto the server.
Add less to your precompilers!
COMPRESS_PRECOMPILERS = ( ('text/less', 'lessc {infile} {outfile}'), )
Now you deploy, and your server compiles the less file. Everything is fantastic!
Now let's add 8 more servers to that and you have to install node, npm, and less on each server?
This is where something doesn't seem right, and I feel like I'm missing something. I believe the Django community has run into this problem before.
My thoughts thus far have been:
Use a post-commit hook to compile the CSS on the developers machine. This means that via django_compressor, we link to the compiled static file in the HTML, and our repository contains both the compiled and non-compiled versions. My only downside to this is it ends up not using half of the benefits of django_compressor and may be tedious for developers?
Suck it up and make node, npm, and less part of the server stack.
Update
I did some additional looking around and it seems that using the COMPRESS_OFFLINE flag (or just --force) with the management command will produce an offline manifest file that does what I need (only tested locally). So setting this up with a pre-deploy hook likes to be the answer.
Of course, still open to other ideas :-)
Coupled with the tips in the comments about COMPRESS_OFFLINE, you could look at django-staticfiles' storage stuff. You can host the static files on amazon s3, for instance, so hosting it all on one static-hosting server and using that from all your servers could also be a nice solution. You wouldn't need to do anything with the static (and compressed) files on the individual servers.
Alternative solution regarding the multiple servers: I've made a custom fabric (docs.fabfile.org) script that installs/configures stuff on our servers. I've only recently started using coffeescript and less, but those two are definitively ending up in my fabfile. That solves the installation problem for me.
(Alternatives to a fabfile are things like a custom debian package with standard dependencies. Or chef or puppet or something similar.)
you can use puppet for the task
I have a reseller account with Media temple. It doesn't support Railo ( http://www.getrailo.com/ ) out of the box but I really do want to use their service, but with some sites using Railo of course.
First port of call was Media temple to assist me...but they don't offer support with resellers on the DV with regards to installing software.
I also Googled and the only thing I can find is this (which looked perfect):
http://jakemauer.com/weblog/railo-on-mediatemple-dv-server/
However, it's out-dated somewhat and I simply do not posses enough technical skill to achieve it (I'm mainly a designer / front-end dev, offering reseller to my clients). One of the first things that guide requires is to get YUM going, but even that I was stuck on. The terminal threw up errors about other files it needed as 'dependencies' and I have no idea how to get that going. I found the process quite complicated. I'm not a server admin :(
I'd be happy to pay someone to do this, but would rather figure it out myself as I'm eager to learn too.
If anyone has experience doing this and can offer insight I'd appreciate it so much.
Thanks,
Michael.
The Railo installer should work just fine on a Media Temple VPS. Documentation on how to launch the Railo installer on a linux machine can be found here:
http://wiki.getrailo.com/wiki/Installation:InstallerDocumentation:LinLaunching
If you don't have a GUI on your server, don't worry, just SSH to your server and run the commands that are posted in the "Command-Line Install" sections.
If you have any problems with any aspect of the install process as outlined in the documentation, I'd recommend the Railo mailing list. The community there (like this one) is quite friendly and can walk you through almost any problems you encounter.
I'm trying to set up a good development environment for a Django project that I will be working on from two different physical locations. I have two Mac machines, one at home and one at work that I do most of my development on. I currently host a Ubuntu virtual machine on one of the machines to host the Django environemnt, install DropBox on it, and edit source code from my Mac. When I save the code file, the changes get synced over DropBox to the Ubuntu VM and the Django development server automatically restarts because of the change. This method has worked well in the past, but I am starting to use DropBox for a lot of other things now and don't want all of that to be downloaded on every virtual machine I use. Plus, I want to start using Eclipse + PyDev to be able to debug code and have code completion. Currently, I use TextEdit which is great, but doesn't support debugging or completion.
So what are my options? I thought about setting up a Parallels VM on a thumb drive that has my entire environment on it (Eclipse included), but that has its own problems. Any other thoughts?
Here is the environment I set up and it has the components you are after. I have used pydev as well and it works but I prefer Komodo.
Things which I think you are missing:
An SCM - Using Dropbox works but there are some real shortcomings by not using a real version control system. Examples include reverting changes, branching, merging, etc. I agree with Simon
Using a virtualenv will really help when developing on multiple platforms.
I do ALL of this on my Mac:)
HTH