I was wondering if it was possible to lock the view (similar to quad view), so that the view doesn't change if I accidentally bump the middle mouse button.
Is there a setting I can change or a script that can do this?
One way you might want to go about this would be to:
Short answer - no.
However this may help...
I assume that you may have a view rotation that took some time to setup, if this is the case you could...
Quad view allows you to lock/unlock the view rotation. This is intended so you can maintain top/front/side views with one user view, but theres nothing stopping you setting up the rotation you want, then locking the view.
If you really want to do this with a script by writing an operator that intercepts view rotate and makes the choice to run or not, but I wouldn't recommend doing this since its fairly involved for such a small change.
You can't lock the rotation of the view but you can lock the pan of the view to always center on the 3D Cursor.

Update: Ok following comment from @Duarte Farrajota Ramos, I have created an AddOn for you:
Save the following text in a text file(Example): lockViewRotation.py
bl_info = {
"name": "Lock View Rotation",
"blender": (2, 80, 0),
"category": "View",
}
import bpy
def draw_lock_rotation(self, context):
layout = self.layout
view = context.space_data
col = layout.column(align=True)
col.prop(view.region_3d, "lock_rotation", text="Lock View Rotation")
def register():
bpy.types.VIEW3D_PT_view3d_lock.append(draw_lock_rotation)
def unregister():
bpy.types.VIEW3D_PT_view3d_lock.remove(draw_lock_rotation)
if name == "main":
register()
In blender go to Edit->Preferences -> Add-ons and Click the "Install..." button and chose the previously saved file
Go to the "Community" tab and search for "Lock View Rotation" Addon and enable it (If you dont find it then close the properties panel and open it again)
Now you will have an option "Lock View Rotation" in your View Lock section so you can create 4 views dragging the corners to split the current view in 4 (top, bottom, right, and perspective) and set the new Lock Rotation on the first 3.
Original Answer:
I have accomplish that in this way:
First Go to to you blender installation path (generally C:\Program Files\Blender Foundation\Blender 2.90\ in my case). And search for the file called: space_view3d.py in Blender 2.##\2.##\scripts\startup\bl_ui\space_view3d.py
Copy this file to a different location (as you wont be able to edit it directly)
Edit this file and search for the line containing: class VIEW3D_PT_view3d_lock(Panel):
this line is the definition for the "lock" options.
Go at the end of the: def draw(self, context): (this is the definition of the draw function for the "lock" options )
Add the following line indented at the end of the function (be careful with indentation):
col.prop(view.region_3d, "lock_rotation", text="Lock Rotation")
class VIEW3D_PT_view3d_lock(Panel):
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = "View"
bl_label = "View Lock"
bl_parent_id = "VIEW3D_PT_view3d_properties"
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False # No animation.
view = context.space_data
col = layout.column(align=True)
sub = col.column()
sub.active = bool(view.region_3d.view_perspective != 'CAMERA' or view.region_quadviews)
sub.prop(view, "lock_object")
lock_object = view.lock_object
if lock_object:
if lock_object.type == 'ARMATURE':
sub.prop_search(
view, "lock_bone", lock_object.data,
"edit_bones" if lock_object.mode == 'EDIT'
else "bones",
text="",
)
else:
subcol = sub.column(heading="Lock")
subcol.prop(view, "lock_cursor", text="To 3D Cursor")
col.prop(view, "lock_camera", text="Camera to View")
# Show the Lock Rotation option on View Properties
col.prop(view.region_3d, "lock_rotation", text="Lock Rotation")
I just have added the last 2 lines, the first line is just a comment, and the second one is the one that's adds the "Lock Rotation" check box to your view locking properties (as specified before)
Replace the original file.
Relaunch Blender
Now create a new Workspace, based on General Layout using the little "+" symbol at the top right for the different workspaces, name it as you want.

Then create 4 views dragging the corners to split the current view in 4 (top, bottom, right, and perspective) and set the new Lock Rotation on the first 3.
def draw_lock(self, context): and append it to the panel bpy.types.VIEW3D_PT_view3d_lock.append(draw_lock)
– batFINGER
Dec 03 '20 at 16:45
Here is an Viewport lock addon, may be the addon is a real decision for Your issue? https://blenderartists.org/t/wlock-an-addon-for-blender-2-8-which-allows-to-lock-3d-view-rotation-using-hotkey-default-alt-w/1163353
This addon allows to lock 3D view rotation (only 3D view) using hotkey. As an additional indicator a 'lock' icon is displayed (can be set up or disabled in Preferences).
Check out this add on by Jason van Gumster(fweeb)
Described like this:
It locks the 3D View to whatever viewing angle you’re currently using, kind of like the ortho views when you use Quad View… but this works for any arbitrary viewing angle.
[...] I discovered that the feature is actually in the Blender Python API, there’s just no way to access it in the UI.So I fixed that.